Skip to content

Commit

Permalink
Add info about callback in options resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
marekkalnik committed Jan 6, 2014
1 parent 6c3d9eb commit 94fe8dc
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions components/options_resolver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,26 @@ There is also an
method, which you can use if you want to add an allowed value to the previously
set allowed values.

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 strpos($value, 'mail') !== false;
}
));
}

Note that using this together with addAllowedValues will not work.

.. versionadded:: 2.5
The callback support for allowed values was added in Symfony 2.5.

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

Expand Down

0 comments on commit 94fe8dc

Please sign in to comment.