Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit921c73f

Browse files
lmillucciOskarStark
authored andcommitted
[OptionResolver] Document the OptionConfigurator
1 parentb357c02 commit921c73f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

‎components/options_resolver.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,38 @@ the option::
782782
This closure receives as argument the value of the option after validating it
783783
and 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+
785817
Performance Tweaks
786818
~~~~~~~~~~~~~~~~~~
787819

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp