Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Config] Allow using an enum FQCN withEnumNode#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 agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

alexandre-daubois
Copy link
Member

@alexandre-dauboisalexandre-daubois commentedJul 9, 2024
edited by OskarStark
Loading

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
IssuesFix#57659
LicenseMIT

This PR allows doing the following with backed enums:

$rootNode    ->children()        ->enumNode('fqcn_enum_node')->enumClass(BackedTestEnum::class)->end()

Then, you can pass enum cases as well as plain strings to the config, which will be automatically converted to an enum case withBackedEnum::tryFrom().

dmaicher, Aerendir, Seldaek, and ste93cry reacted with hooray emoji
@alexandre-daubois
Copy link
MemberAuthor

alexandre-daubois commentedJul 9, 2024
edited
Loading

Thanks for the review! I didn't answer to each message individually to avoid spamming your notifications but I addressed everything

@alexandre-dauboisalexandre-dauboisforce-pushed theconfig-enum-node-class branch 3 times, most recently from6d25b9b to7808738CompareJuly 9, 2024 14:56
@Seldaek
Copy link
Member

Great stuff overall, thanks for picking this up! :)

alexandre-daubois reacted with rocket emoji

@alexandre-dauboisalexandre-dauboisforce-pushed theconfig-enum-node-class branch 2 times, most recently fromf1daab5 toba522e8CompareJuly 10, 2024 14:27
Copy link
Member

@SeldaekSeldaek left a 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 😅

alexandre-daubois reacted with laugh emoji
@Seldaek
Copy link
Member

Ah an interesting problem came up herehttps://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::cases() would?

@alexandre-daubois
Copy link
MemberAuthor

alexandre-daubois commentedJul 10, 2024
edited
Loading

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,EnumNodeDefinition (roughly, when using->enumNode(...)->enumFqcn(...)) will throw if the enum doesn't exist. Seems safe to me 🤔

I also think that people will use it with the::class syntax rather than a raw string, which will make PHP complain if the enum doesn't exist as well

@Seldaek
Copy link
Member

Yes it seems safe, but it doesn't solve the problem in the other PR :)

I also think that people will use it with the::class syntax rather than a raw string, which will make PHP complain if the enum doesn't exist as well

That is not true unfortunatelyhttps://3v4l.org/ibsvJ

@alexandre-daubois
Copy link
MemberAuthor

alexandre-daubois commentedJul 10, 2024
edited
Loading

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$values and it's a string, then we consider that it must always be the FQCN of an enum. Why not, although I feel like it's a bit of a hack when I write it.

@Seldaek
Copy link
Member

Sorry you lost me there. You already have->enumFqcn() so it is clear that what is passed in there must be a valid enum class name, and enum_exists will ensure that passingRandomNonExistantEnum::class will fail at runtime at least. I think let's leave this PR as is for now.

@alexandre-daubois
Copy link
MemberAuthor

Ah yes I forgot a bit of context, sorry. Actually I was talking about the standalone use ofEnumNode, withoutEnumNodeDefinition::enumFqcn().

But anyway, let's see what others think of the current state yes! 👍

@alexandre-dauboisalexandre-dauboisforce-pushed theconfig-enum-node-class branch 2 times, most recently from315c6b3 to1f036a0CompareSeptember 3, 2024 19:55
@javiereguiluzjaviereguiluz added the ❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze" labelOct 3, 2024
@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
Copy link
Member

@derrabusderrabus left a 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?

alexandre-daubois reacted with rocket emoji
Copy link
Member

@nicolas-grekasnicolas-grekas left a 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

@alexandre-dauboisalexandre-dauboisforce-pushed theconfig-enum-node-class branch 2 times, most recently from95b3c59 to6529b5aCompareFebruary 11, 2025 12:25
@alexandre-daubois
Copy link
MemberAuthor

Thank you for the review. I updated to have as many early return/throw as possible as well as improved the exception messages.

@fabpot
Copy link
Member

Thank you@alexandre-daubois.

Seldaek reacted with hooray emoji

@fabpotfabpot merged commit6b02c77 intosymfony:7.3Feb 26, 2025
10 of 11 checks passed
@fabpotfabpot mentioned this pull requestMay 2, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@derrabusderrabusderrabus requested changes

@stofstofstof requested changes

@fabpotfabpotfabpot approved these changes

@SeldaekSeldaekSeldaek approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees
No one assigned
Labels
ConfigFeature❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze"Status: Reviewed
Projects
None yet
Milestone
7.3
Development

Successfully merging this pull request may close these issues.

[Config] Support passing the value of backed enums in enumNode
8 participants
@alexandre-daubois@Seldaek@fabpot@nicolas-grekas@stof@derrabus@javiereguiluz@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp