-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Config] Fix support for attributes on class constants and enum cases #61079
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
[Config] Fix support for attributes on class constants and enum cases #61079
Conversation
230a888
to
b3f6c68
Compare
ReflectionClassResource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am curious about your use case for enums with configuration.
I have a compiler that creates PHP code based on some classes and enums I declare in my application. I use the resources to quickly check if there are changes and if I should recompile. To be specific: it's creating Webonyx GraphQL type files, which are annoying to create by hand (arrays etc). Therefore we have our own abstraction with attributes. |
@GromNaN that is a valid use case for these classes, right? |
Works for me as a bugfix on 6.4
Doesn't this mean that the more generic fix is to fix support for attributes on class constants? |
Thanks. I'll rebase this PR later.
Sure, but that's a PHP 8.5 feature: https://wiki.php.net/rfc/attributes-on-constants Maybe we should also add support for that already? |
That RFC is for constants. Here we need class-constants, which do support attributes in PHP 8.1: |
ReflectionClassResource
1134b52
to
c8844f4
Compare
@nicolas-grekas Implemented it for class constants. I think this solution is much better :) Thanks! |
src/Symfony/Component/Config/Resource/ReflectionClassResource.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Config/Resource/ReflectionClassResource.php
Outdated
Show resolved
Hide resolved
c8844f4
to
e39e189
Compare
src/Symfony/Component/Config/Resource/ReflectionClassResource.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Config/Resource/ReflectionClassResource.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Config/Resource/ReflectionClassResource.php
Outdated
Show resolved
Hide resolved
440bf0a
to
3de864d
Compare
src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php
Outdated
Show resolved
Hide resolved
1cc544b
to
51b2c78
Compare
Thank you @ruudk. |
I'm using ReflectionClassResource in a project to track changes of files. I noticed that attributes on enum cases were not tracked properly. The cases were visible, because the enum cases are available as class constants.
But the attributes were missing.
This solves the problem.
Not sure if we should see this as a bug or feature. I think it's a bug.