-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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] Support passing the value of backed enums in enumNode #57659
Comments
The only downside I could see, which is a faux pas anyway, is when someone changes the value of an enum case, to correct it, while keeping the case in-tact. However, that's a risk one has to accept when configuring without explicitly using the enum case in the first place. Also, this same risk is present on non-enum configuration. At the very least, an enum already denotes the maintainer is more careful about selecting allowed values for configuration. The risk could even be mitigated by the maintainer through overriding the 👍 I'm really stoked for this enhancement. |
I really like this feature! I gave a try on the implementation, tell me what you think 🙂 |
Description
This idea came up while looking at this mess. I figured it would be nice if you could just pass
->enumNode(BackedEnum::cases())
or even->enumNode(BackedEnum::class)
. Turns out it is possible (the former) thanks to #49098 but then if you do that the users have to also manage to create enum cases likefoo: !php/enum \App\Enum\FooEnum::Bar
, which requires a lot of internal knowledge and is not super user friendly.So my request is.. Could we make it so that if all enumNode cases are actual enum instances and there is no plain string in there, and the enum is backed, then if a string is passed in as value in the config it would do
enum::tryFrom(string)
to convert it automatically?Example
foo: "bar"
would auto-convert to\App\Enum\FooEnum::Bar
The text was updated successfully, but these errors were encountered: