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] AddArrayNodeDefinition::acceptAndWrap() to list alternative types that should be accepted and wrapped in an array#51273

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
fabpot merged 1 commit intosymfony:7.4fromnicolas-grekas:config-cast-to-array
Sep 23, 2025

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedAug 4, 2023
edited
Loading

QA
Branch?6.4
Bug fix?no
New feature?no
Deprecations?no
Tickets-
LicenseMIT
Doc PR-

With#58450, we lost some type info when generating config builders, by preventing#44166 to work correctly.

This PR improves the description of config trees by adding anArrayNodeDefinition::acceptAndWrap() method that allows one to declare which alternative types should be accepted at array-node levels. This declaration then triggers the wrapping of such cases into arrays, and also hints the config builder generator so that it can generate more accurate types for configurator methods.

@maxbeckers

This comment was marked as outdated.

if (isset($this->normalization)) {
$node->setNormalizationClosures($this->normalization->before);
$node->setNormalizedTypes($this->normalization->declaredTypes);
$node->setNormalizedTypes($this->allowedTypes ??$this->normalization->declaredTypes);
Copy link
Member

Choose a reason for hiding this comment

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

Why is$this->normalization->declaredTypes filled normally ? and why do we need to add this new$this->allowedTypes property instead of using the existing feature (which gets ignored entirely) ?

Copy link
MemberAuthor

@nicolas-grekasnicolas-grekasSep 17, 2025
edited
Loading

Choose a reason for hiding this comment

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

I was wondering the same until I (re)discovered#44166, which is based on that: sniffing for allowed types in what I'd call an indirect approach. I'm here proposing a more explicit approach, which wins over the implicit one when used.

Copy link
Member

Choose a reason for hiding this comment

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

overriding entirely the types inferred from the normalization looks wrong to me (unless we want to deprecate that behavior).
And the suggested API does not play well with nodes supporting multiple normalization rules.

Copy link
MemberAuthor

@nicolas-grekasnicolas-grekasSep 18, 2025
edited
Loading

Choose a reason for hiding this comment

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

It has to be this way, seeL1532 in theConfiguration class for an example: implicit types are loose and too many times we have to fallback tomixed (->always(),->ifTrue($fn), etc.). Being explicit need to override the implicit collection of possible types - as not all types managed by normalizers have to be accepted at the config builder level (because of the XML loader mainly).
Which means this has to be the way to go.

I renamed the new method->acceptAndWrap() instead of->castToArray(). This is both more explicit and more accurate.

@nicolas-grekasnicolas-grekas changed the title[Config] Improve casting config nodes to array[Config] AddArrayNodeDefinition::acceptAndWrap() to list alternative types that should be accepted and wrapped in an arraySep 18, 2025
@nicolas-grekasnicolas-grekasforce-pushed theconfig-cast-to-array branch 3 times, most recently from37153cf to73b4c37CompareSeptember 18, 2025 13:10
@nicolas-grekas
Copy link
MemberAuthor

Thanks for the review@GromNaN - PR updated.

ExprBuilder::TYPE_STRING =>is_string(...),
ExprBuilder::TYPE_BOOL =>is_bool(...),
ExprBuilder::TYPE_NULL =>is_null(...),
ExprBuilder::TYPE_BACKED_ENUM =>staticfn ($v) =>$vinstanceof \BackedEnum,
Copy link
Member

Choose a reason for hiding this comment

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

That's right, let's keep that for a future improvement.

GromNaN added a commit to GromNaN/DoctrineMongoDBBundle that referenced this pull requestSep 22, 2025
@fabpot
Copy link
Member

Thank you@nicolas-grekas.

@fabpotfabpot merged commita30f387 intosymfony:7.4Sep 23, 2025
7 of 12 checks passed
@nicolas-grekasnicolas-grekas deleted the config-cast-to-array branchSeptember 23, 2025 07:14
Kocal added a commit to Kocal/symfony-ux that referenced this pull requestSep 25, 2025
Kocal added a commit to Kocal/symfony-ux that referenced this pull requestSep 25, 2025
Kocal added a commit to symfony/ux that referenced this pull requestSep 25, 2025
… from Kernel for testing (Kocal)This PR was merged into the 2.x branch.Discussion---------- Remove explicit configuration `twig.exception_controller` from Kernel for testing| Q              | A| -------------- | ---| Bug fix?       | yes| New feature?   | no <!-- please update src/**/CHANGELOG.md files -->| Deprecations?  | no <!-- if yes, also update UPGRADE-*.md and src/**/CHANGELOG.md -->| Documentation? | no <!-- required for new features, or documentation updates -->| Issues         | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->| License        | MITRelated tosymfony/symfony#51273 (comment)Fixhttps://github.com/symfony/ux/actions/runs/17999302594/job/51204828176?pr=3102Commits-------f46109a Remove explicit configuration `twig.exception_controller` from Kernel for testing
symfony-splitter pushed a commit to symfony/ux-notify that referenced this pull requestSep 25, 2025
symfony-splitter pushed a commit to symfony/ux-chartjs that referenced this pull requestSep 25, 2025
symfony-splitter pushed a commit to symfony/ux-lazy-image that referenced this pull requestSep 25, 2025
symfony-splitter pushed a commit to symfony/ux-map that referenced this pull requestSep 25, 2025
symfony-splitter pushed a commit to symfony/ux-vue that referenced this pull requestSep 25, 2025
symfony-splitter pushed a commit to symfony/ux-cropperjs that referenced this pull requestSep 25, 2025
symfony-splitter pushed a commit to symfony/ux-svelte that referenced this pull requestSep 25, 2025
symfony-splitter pushed a commit to symfony/ux-react that referenced this pull requestSep 25, 2025
symfony-splitter pushed a commit to symfony/ux-toggle-password that referenced this pull requestSep 25, 2025
symfony-splitter pushed a commit to symfony/ux-dropzone that referenced this pull requestSep 25, 2025
fabpot added a commit that referenced this pull requestSep 29, 2025
…nodes that can be enabled or disabled (nicolas-grekas)This PR was merged into the 7.4 branch.Discussion----------[Config] Config builders should accept booleans for array nodes that can be enabled or disabled| Q             | A| ------------- | ---| Branch?       | 7.4| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Issues        | -| License       | MITContinuing my journey on the config component, after#51273That could be considered as a bugfix, but it's not worth fixing on lower branches because nobody is using this missing capability - by definition.So: this allows doing eg `->lock(false)` to disable locks, as expected when the node definition has `->treatFalseLike(['enabled' => false])`Note that I didn't turn `->treatNullLike(['enabled' => true])` into accepting `null` as I don't see the point of allowing  `->lock(null)` when one can use  `->lock(true)`.Commits-------633169f [Config] Config builders should accept booleans for array nodes that can be enabled or disabled
This was referencedOct 27, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@fabpotfabpotfabpot approved these changes

@GromNaNGromNaNGromNaN approved these changes

@wouterjwouterjAwaiting requested review from wouterj

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

@ycerutoycerutoAwaiting requested review from ycerutoyceruto is a code owner

+1 more reviewer

@maxbeckersmaxbeckersmaxbeckers left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

7.4

Development

Successfully merging this pull request may close these issues.

7 participants

@nicolas-grekas@maxbeckers@fabpot@GromNaN@stof@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp