Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Routing] Load attributes from a directory following PSR-4 #47881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
derrabus opened this issue Oct 17, 2022 · 2 comments · Fixed by #47916
Closed

[Routing] Load attributes from a directory following PSR-4 #47881

derrabus opened this issue Oct 17, 2022 · 2 comments · Fixed by #47916

Comments

@derrabus
Copy link
Member

derrabus commented Oct 17, 2022

Description

A client I'm working with uses SourceGuardian to encrypt their product before delivering it to their customers. They want to use Symfony's routing component and PHP attributes. Reading attributes from encrypted code works fine because attributes are part of the encrypted bytecode.

However, the component attempts to parse the PHP files it is supposed to extract routes from in order to find out which classes it declares:

$tokens = token_get_all(file_get_contents($file));

This of course fails in our scenario because the source code is not readable anymore. In our application, we currently work around this problem by extending AnnotationDirectoryLoader and overriding the findClass() method and constructing the class name under the assumption that the project follows PSR-4.

Parsing PHP code to gather class names in projects that follow PSR-4 feels unnecessary. In addition, the service discovery feature of the DI component also uses PSR-4 and reflection instead of parsing PHP files. I think, we should offer a PSR-4 attribute loader for the routing component and consider deprecating the PHP parsing logic.

Example

No response

@nicolas-grekas
Copy link
Member

If we deprecate annotations, this code will go away, isn't it?

@derrabus
Copy link
Member Author

No, this code stays because it is used to discover the list of controller classes that we want to search for annotations/attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants