Skip to content

Commit 1da928a

Browse files
committed
minor #20719 [OptionsResolver] Update nested options examples to use 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
2 parents 38eee53 + 159a150 commit 1da928a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

components/options_resolver.rst

+15-5
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ default value::
662662

663663
public function configureOptions(OptionsResolver $resolver): void
664664
{
665-
$resolver->setDefault('spool', function (OptionsResolver $spoolResolver): void {
665+
$resolver->setOptions('spool', function (OptionsResolver $spoolResolver): void {
666666
$spoolResolver->setDefaults([
667667
'type' => 'file',
668668
'path' => '/path/to/spool',
@@ -686,6 +686,16 @@ default value::
686686
],
687687
]);
688688

689+
.. deprecated:: 7.3
690+
691+
Defining nested option via :method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::setDefault`
692+
was deprecated since Symfony 7.3, use the :method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::setOptions`
693+
instead. Allowing to define default values for prototyped options.
694+
695+
.. versionadded:: 7.3
696+
697+
The :method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::setOptions` was introduced in Symfony 7.3.
698+
689699
Nested options also support required options, validation (type, value) and
690700
normalization of their values. If the default value of a nested option depends
691701
on another option defined in the parent level, add a second ``Options`` argument
@@ -698,7 +708,7 @@ to the closure to access to them::
698708
public function configureOptions(OptionsResolver $resolver): void
699709
{
700710
$resolver->setDefault('sandbox', false);
701-
$resolver->setDefault('spool', function (OptionsResolver $spoolResolver, Options $parent): void {
711+
$resolver->setOptions('spool', function (OptionsResolver $spoolResolver, Options $parent): void {
702712
$spoolResolver->setDefaults([
703713
'type' => $parent['sandbox'] ? 'memory' : 'file',
704714
// ...
@@ -721,13 +731,13 @@ In same way, parent options can access to the nested options as normal arrays::
721731

722732
public function configureOptions(OptionsResolver $resolver): void
723733
{
724-
$resolver->setDefault('spool', function (OptionsResolver $spoolResolver): void {
734+
$resolver->setOptions('spool', function (OptionsResolver $spoolResolver): void {
725735
$spoolResolver->setDefaults([
726736
'type' => 'file',
727737
// ...
728738
]);
729739
});
730-
$resolver->setDefault('profiling', function (Options $options): void {
740+
$resolver->setOptions('profiling', function (Options $options): void {
731741
return 'file' === $options['spool']['type'];
732742
});
733743
}
@@ -748,7 +758,7 @@ with ``host``, ``database``, ``user`` and ``password`` each.
748758

749759
The best way to implement this is to define the ``connections`` option as prototype::
750760

751-
$resolver->setDefault('connections', function (OptionsResolver $connResolver): void {
761+
$resolver->setOptions('connections', function (OptionsResolver $connResolver): void {
752762
$connResolver
753763
->setPrototype(true)
754764
->setRequired(['host', 'database'])

0 commit comments

Comments
 (0)