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

Skip to content

[Config] Support passing the value of backed enums in enumNode #57659

Closed
@Seldaek

Description

@Seldaek

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 like foo: !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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions