-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Config] Allow using an enum FQCN with EnumNode
#57686
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 a 8000 gree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/Symfony/Component/Config/Definition/Builder/EnumNodeDefinition.php
Outdated
Show resolved
Hide resolved
a84a01b
to
1b7d1e9
Compare
Thanks for the review! I didn't answer to each message individually to avoid spamming your notifications but I addressed everything |
6d25b9b
to
7808738
Compare
Great stuff overall, thank 8000 s for picking this up! :) |
f1daab5
to
ba522e8
Compare
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.
LGTM now from an end user perspective, but the core team might have more feedback 😅
Ah an interesting problem came up here https://github.com/symfony/symfony/pull/57653/files#r1671760696 - what if the enum class is not defined? Should it make an empty value set then? Or error loudly but in a nicer way than just calling |
In the constructor, I check the existence of the enum. If it doesn't exist, it will treat it as a simple string. I think it is enough, otherwise I'm affraid it will complexify the whole thing a lot. Additionally, I also think that people will use it with the |
Yes it seems safe, but it doesn't solve the problem in the other PR :)
That is not true unfortunately https://3v4l.org/ibsvJ |
Ah yes indeed... In fact, making an assertion that a string looks like an FQCN seems a bit brittle to me. Another solution that could be considered is that, if only one value is passed to |
Sorry you lost me there. You already have |
Ah yes I forgot a bit of context, sorry. Actually I was talking about the standalone use of But anyway, let's see what others think of the current state yes! 👍 |
...mponent/Config/Tests/Builder/Fixtures/PrimitiveTypes/Symfony/Config/PrimitiveTypesConfig.php
Show resolved
Hide resolved
ba522e8
to
98794a0
Compare
315c6b3
to
1f036a0
Compare
1f036a0
to
c034e3e
Compare
c034e3e
to
a31c025
Compare
a31c025
to
d060265
Compare
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.
Let's get this over the finish line, shall we?
d060265
to
bc2ab61
Compare
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.
Minor things on my side
95b3c59
to
6529b5a
Compare
Thank you for the review. I updated to have as many early return/throw as possible as well as improved the exception messages. |
6529b5a
to
836d0a7
Compare
836d0a7
to
2b3b4bf
Compare
Thank you @alexandre-daubois. |
This PR allows doing the following with backed enums:
Then, you can pass enum cases as well as plain strings to the config, which will be automatically converted to an enum case with
BackedEnum::tryFrom()
.