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 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
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
Copy link
Member

Choose a reason for hiding this comment

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

[....] process, you can [...]

as an allowed value::

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

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

Choose a reason for hiding this comment

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

Should be

return false !== strpos($value, 'mail');

to be consistent with the Symfony coding standards.

}
Copy link
Member

Choose a reason for hiding this comment

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

missing comma after the brace

));
}

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 should be placed in an inline code block, put it in double backticks.

Copy link
Member

Choose a reason for hiding this comment

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

Imho this should be put in a note or caution block.


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

Choose a reason for hiding this comment

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

was introduced in Symfony 2.5.

And this message should be placed before this addition, instead of after it imo

Copy link
Member

Choose a reason for hiding this comment

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

👍


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

Expand Down