Skip to content
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] Allow enum values in EnumNode #49098

Merged
merged 1 commit into from Feb 4, 2023

Conversation

fancyweb
Copy link
Contributor

Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? no
Tickets -
License MIT
Doc PR -

This PR allows adding 1..N case(s) from the same enum to the allowed values of EnumNode:

// Allow all cases
->enumNode('foo', FooEnum::cases())

// Allow some cases with some other scalar values
->enumNode('foo', [true, false, FooEnum::Foo, FooEnum::Bar])

The two benefits are not having to reconstruct the enum instance at process time and being able to use the real enum directly in PHP config files:

$config
    ->foo(FooEnum::Bar);

YAML config files can also pass an enum value:

foo: !php/enum \App\Enum\FooEnum::Bar

AFAIK, XML config files can't pass an enum value, which would mean they could not be used in this case.

@carsonbot carsonbot added this to the 6.3 milestone Jan 25, 2023
@fancyweb fancyweb force-pushed the config/enum-in-enum-node branch 2 times, most recently from ae1b604 to 4d550ad Compare January 25, 2023 09:42
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for xml, it's possible to create and reference an enum parameter I suppose?

src/Symfony/Component/Config/Definition/EnumNode.php Outdated Show resolved Hide resolved
@fabpot
Copy link
Member

fabpot commented Feb 4, 2023

Thank you @fancyweb.

@fabpot fabpot merged commit 1655d17 into symfony:6.3 Feb 4, 2023
@fancyweb fancyweb deleted the config/enum-in-enum-node branch February 6, 2023 08:02
@fabpot fabpot mentioned this pull request May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants