@@ -662,7 +662,7 @@ default value::
662
662
663
663
public function configureOptions(OptionsResolver $resolver): void
664
664
{
665
- $resolver->setDefault ('spool', function (OptionsResolver $spoolResolver): void {
665
+ $resolver->setOptions ('spool', function (OptionsResolver $spoolResolver): void {
666
666
$spoolResolver->setDefaults([
667
667
'type' => 'file',
668
668
'path' => '/path/to/spool',
@@ -686,6 +686,16 @@ default value::
686
686
],
687
687
]);
688
688
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
+
689
699
Nested options also support required options, validation (type, value) and
690
700
normalization of their values. If the default value of a nested option depends
691
701
on another option defined in the parent level, add a second ``Options `` argument
@@ -698,7 +708,7 @@ to the closure to access to them::
698
708
public function configureOptions(OptionsResolver $resolver): void
699
709
{
700
710
$resolver->setDefault('sandbox', false);
701
- $resolver->setDefault ('spool', function (OptionsResolver $spoolResolver, Options $parent): void {
711
+ $resolver->setOptions ('spool', function (OptionsResolver $spoolResolver, Options $parent): void {
702
712
$spoolResolver->setDefaults([
703
713
'type' => $parent['sandbox'] ? 'memory' : 'file',
704
714
// ...
@@ -721,13 +731,13 @@ In same way, parent options can access to the nested options as normal arrays::
721
731
722
732
public function configureOptions(OptionsResolver $resolver): void
723
733
{
724
- $resolver->setDefault ('spool', function (OptionsResolver $spoolResolver): void {
734
+ $resolver->setOptions ('spool', function (OptionsResolver $spoolResolver): void {
725
735
$spoolResolver->setDefaults([
726
736
'type' => 'file',
727
737
// ...
728
738
]);
729
739
});
730
- $resolver->setDefault ('profiling', function (Options $options): void {
740
+ $resolver->setOptions ('profiling', function (Options $options): void {
731
741
return 'file' === $options['spool']['type'];
732
742
});
733
743
}
@@ -748,7 +758,7 @@ with ``host``, ``database``, ``user`` and ``password`` each.
748
758
749
759
The best way to implement this is to define the ``connections `` option as prototype::
750
760
751
- $resolver->setDefault ('connections', function (OptionsResolver $connResolver): void {
761
+ $resolver->setOptions ('connections', function (OptionsResolver $connResolver): void {
752
762
$connResolver
753
763
->setPrototype(true)
754
764
->setRequired(['host', 'database'])
0 commit comments