File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -782,6 +782,38 @@ the option::
782782This closure receives as argument the value of the option after validating it
783783and before normalizing it when the option is being resolved.
784784
785+ Chaining option configurations
786+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
787+
788+ In many cases you may need to define multiple configurations for each option.
789+ For example, suppose the ``Mailer `` class has an ``host `` option that is required
790+ and a ``transport `` option which can be one of ``sendmail ``, ``mail `` and ``smtp ``.
791+ You can improve the readability of the code avoiding to duplicate option name for
792+ each configuration using the method
793+ :method: `Symfony\\ Component\\ OptionsResolver\\ OptionsResolver::define` `::
794+
795+ // ...
796+ class Mailer
797+ {
798+ // ...
799+ public function configureOptions(OptionsResolver $resolver)
800+ {
801+ // ...
802+ $resolver->define('host')
803+ ->required()
804+ ->default('smtp.example.org')
805+ ->allowedTypes('string');
806+ $resolver->define('transport')
807+ ->required()
808+ ->default('transport')
809+ ->allowedValues(['sendmail', 'mail', 'smtp']);
810+ }
811+ }
812+
813+ .. versionadded :: 5.1
814+
815+ The ``define() `` method was introduced in Symfony 5.1.
816+
785817Performance Tweaks
786818~~~~~~~~~~~~~~~~~~
787819
You can’t perform that action at this time.
0 commit comments