Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.2k
[OptionsResolver] Update nested options examples to usesetOptions
instead ofsetDefault
#20719
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -662,7 +662,7 @@ default value:: | ||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setOptions('spool', function (OptionsResolver $spoolResolver): void { | ||
$spoolResolver->setDefaults([ | ||
'type' => 'file', | ||
'path' => '/path/to/spool', | ||
@@ -686,6 +686,16 @@ default value:: | ||
], | ||
]); | ||
.. deprecated:: 7.3 | ||
Defining nested option via :method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::setDefault` | ||
was deprecated since Symfony 7.3, use the :method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::setOptions` | ||
instead. Allowing to define default values for prototyped options. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'm not sure about this deprecation block. Is it needed in this case, or would the replacement + versionadded note be enough? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Yes, sometimes it's difficult to decide if we should add such a block. At the end, I left it so anyone searching for "setDefault" can still find this page. Thanks! | ||
.. versionadded:: 7.3 | ||
The :method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::setOptions` was introduced in Symfony 7.3. | ||
Nested options also support required options, validation (type, value) and | ||
normalization of their values. If the default value of a nested option depends | ||
on another option defined in the parent level, add a second ``Options`` argument | ||
@@ -698,7 +708,7 @@ to the closure to access to them:: | ||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setDefault('sandbox', false); | ||
$resolver->setOptions('spool', function (OptionsResolver $spoolResolver, Options $parent): void { | ||
$spoolResolver->setDefaults([ | ||
'type' => $parent['sandbox'] ? 'memory' : 'file', | ||
// ... | ||
@@ -721,13 +731,13 @@ In same way, parent options can access to the nested options as normal arrays:: | ||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setOptions('spool', function (OptionsResolver $spoolResolver): void { | ||
$spoolResolver->setDefaults([ | ||
'type' => 'file', | ||
// ... | ||
]); | ||
}); | ||
$resolver->setOptions('profiling', function (Options $options): void { | ||
return 'file' === $options['spool']['type']; | ||
}); | ||
} | ||
@@ -748,7 +758,7 @@ with ``host``, ``database``, ``user`` and ``password`` each. | ||
The best way to implement this is to define the ``connections`` option as prototype:: | ||
$resolver->setOptions('connections', function (OptionsResolver $connResolver): void { | ||
$connResolver | ||
->setPrototype(true) | ||
->setRequired(['host', 'database']) | ||