From 94fe8dc430f5f70971bb80218df285ddaef2079e Mon Sep 17 00:00:00 2001 From: Marek Kalnik Date: Mon, 6 Jan 2014 23:14:48 +0100 Subject: [PATCH 1/2] Add info about callback in options resolver --- components/options_resolver.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/components/options_resolver.rst b/components/options_resolver.rst index 9a62f8581fa..d14ee678278 100644 --- a/components/options_resolver.rst +++ b/components/options_resolver.rst @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~ From 8231230f426e95ff0f2661b33a2555c0b88b27cd Mon Sep 17 00:00:00 2001 From: Marek Kalnik Date: Mon, 13 Jan 2014 20:15:38 +0100 Subject: [PATCH 2/2] Fix according to PR comments --- components/options_resolver.rst | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/components/options_resolver.rst b/components/options_resolver.rst index d14ee678278..56cfa62d4b1 100644 --- a/components/options_resolver.rst +++ b/components/options_resolver.rst @@ -305,7 +305,11 @@ 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 +.. 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:: // ... @@ -315,15 +319,14 @@ as an allowed value:: $resolver->setAllowedValues(array( 'transport' => function($value) { - return strpos($value, 'mail') !== false; - } + return false !== strpos($value, 'mail'); + }, )); } -Note that using this together with addAllowedValues will not work. +.. caution:: -.. versionadded:: 2.5 - The callback support for allowed values was added in Symfony 2.5. + Note that using this together with ``addAllowedValues`` will not work. Configure allowed Types ~~~~~~~~~~~~~~~~~~~~~~~