8000 [OptionsResolver] Documenting nested options feature by yceruto · Pull Request #9995 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[OptionsResolver] Documenting nested options feature #9995

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removing some // ... :)
  • Loading branch information
yceruto committed Dec 10, 2018
commit 44e1a3d26df7f06fe24d587d74766752b2bc5c1e
11 changes: 3 additions & 8 deletions components/options_resolver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -646,13 +646,12 @@ a closure as the default value of the ``spool`` option with a :class:`Symfony\\C
argument. Based on this instance, you can define the options under ``spool`` and its desired default
value::

// ...
class Mailer
{
// ...

public function configureOptions(OptionsResolver $resolver)
{
// ...
$resolver->setDefault('spool', function (OptionsResolver $spoolResolver) {
$spoolResolver->setDefaults(array(
'type' => 'file',
Expand Down Expand Up @@ -683,20 +682,18 @@ normalization and more.
If the default value of a child option depend on another option defined in parent level,
adds a second ``Options`` argument to the closure::

// ...
class Mailer
{
// ...

public function configureOptions(OptionsResolver $resolver)
{
// ...
$resolver->setDefault('sandbox', false);
$resolver->setDefault('spool', function (OptionsResolver $spoolResolver, Options $parent) {
$spoolResolver->setDefaults(array(
'type' => $parent['sandbox'] ? 'memory' : 'file',
// ...
));
// ...
});
}
}
Expand All @@ -708,19 +705,17 @@ adds a second ``Options`` argument to the closure::

In same way, parent options can access the child option as follows::

// ...
class Mailer
{
// ...

public function configureOptions(OptionsResolver $resolver)
{
// ...
$resolver->setDefault('spool', function (OptionsResolver $spoolResolver) {
$spoolResolver->setDefaults(array(
'type' => 'file',
// ...
));
// ...
});
$resolver->setDefault('profiling', function (Options $options) {
return 'file' === $options['spool']['type'];
Expand Down
0