Skip to content
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

Add info about callback in options resolver #3437

Merged
merged 2 commits into from
Jan 21, 2014
Merged
Changes from all commits
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
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addAllowedValues()


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

Expand Down