-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[OptionsResolver] Deprecate defining nested options via setDefault()
use setOptions()
instead
#59618
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5aee060
to
616e8fc
Compare
Psalm failure is a false positive. |
616e8fc
to
48d601f
Compare
48d601f
to
042cdfe
Compare
setDefault()
use setNested()
insteadsetDefault()
use setOptions()
instead
877a720
to
0ad4b89
Compare
src/Symfony/Component/OptionsResolver/Debug/OptionsResolverIntrospector.php
Outdated
Show resolved
Hide resolved
3ed6e2d
to
de64012
Compare
src/Symfony/Component/OptionsResolver/Debug/OptionsResolverIntrospector.php
Outdated
Show resolved
Hide resolved
de64012
to
1172bda
Compare
nicolas-grekas
approved these changes
Feb 5, 2025
stof
reviewed
Feb 5, 2025
src/Symfony/Component/OptionsResolver/Debug/OptionsResolverIntrospector.php
Show resolved
Hide resolved
1172bda
to
b0bb9a1
Compare
Just fixing conflicts |
fabpot
approved these changes
Feb 26, 2025
Thank you @yceruto. |
fabpot
added a commit
that referenced
this pull request
Mar 1, 2025
…ebugCommand` (yceruto) This PR was merged into the 7.3 branch. Discussion ---------- [Form] Add support for displaying nested options in `DebugCommand` | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT Addressing #59618 (comment) ```bash $ bin/console debug:form FooType baz --format=json ``` being `baz` a nested option of the `FooType`, output example in JSON format: ```json { "required": false, "default": [], "is_lazy": false, "has_normalizer": false, "has_nested_options": true, "nested_options": { "foo": { "required": true, "default": true, "is_lazy": false, "has_normalizer": false, "has_nested_options": false }, "bar": { "required": false, "default": true, "is_lazy": false, "has_normalizer": false, "has_nested_options": false } } } ``` The new additions here are the `has_nested_options` and `nested_options` entries. Cheers! Commits ------- 2a6d2d4 Add support for displaying nested options in DebugCommand
javiereguiluz
added a commit
to symfony/symfony-docs
that referenced
this pull request
Mar 19, 2025
…`setOptions` instead of `setDefault` (yceruto) This PR was merged into the 7.3 branch. Discussion ---------- [OptionsResolver] Update nested options examples to use `setOptions` instead of `setDefault` closes #20705 PR symfony/symfony#59618 Commits ------- 159a150 Update nested options examples to use setOptions instead of setDefault
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
this removes unnecessary limitations that I hadn't considered when introducing nested options feature in #27291.
1. Allow defining default values for nested options
Imagine you want to define the following nested option in a generic form type:
then, I'd like to define a concrete type with a default value for it.
this might seem unexpected, but the fact is that the nested definition for
foo
option inConcreteType
is gone. As a result, when resolved, thefoo
option will have a default value (['bar' => 23]
) but without any constraints, allowing end users any value/type to be passed through this option forConcreteType
instancesFor example, passing
['foo' => false]
as options forConcreteType
would be allowed, instead of requiring an array wherebar
expects an integer value.2. Allow defining lazy default for nested options
the same problem would occur with a lazy default for a nested definition:
the issue here is the same as in the previous example, meaning this new default essentially overrides/removes the original nested definition
the two features mentioned earlier are now supported by introducing a new method
setOptions()
, which separates the nested definition from its default value (whether direct or lazy). Additionally this PR deprecates the practice of defining nested options usingsetDefault()
methodthis also enables the ability to set default values for prototyped options, which wasn't possible before. For example:
cheers!