Skip to content

Commit

Permalink
feature #3437 Add info about callback in options resolver (marekkalnik)
Browse files Browse the repository at this point in the history
This PR was merged into the master branch.

Discussion
----------

Add info about callback in options resolver

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes (symfony/symfony#8375)
| Applies to    | 2.5+
| Fixed tickets |

The documentation for the PR (pending) about validation callbacks in OptionsResolver.

Commits
-------

8231230 Fix according to PR comments
94fe8dc Add info about callback in options resolver
  • Loading branch information
weaverryan committed Jan 21, 2014
2 parents c6ac96c + 8231230 commit 0a0bf4c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions components/options_resolver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,29 @@ There is also an
method, which you can use if you want to add an allowed value to the previously
set allowed values.

.. versionadded:: 2.5

The callback support for allowed values was introduced in Symfony 2.5.

If you need to add some more logic to the value validation process, you can pass a callable
as an allowed value::

// ...
protected function setDefaultOptions(OptionsResolverInterface $resolver)
{
// ...

$resolver->setAllowedValues(array(
'transport' => function($value) {
return false !== strpos($value, 'mail');
},
));
}

.. caution::

Note that using this together with ``addAllowedValues`` will not work.

Configure allowed Types
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down

0 comments on commit 0a0bf4c

Please sign in to comment.