symfony/symfony — pull request #13067 by SofHad (2014-12-21 18:15:02+00:00)
Title: [OptionsResolver] Added Ability to filter by regex the allowed values

| Q | A
| ------------- | ---
| Bug fix? | [no]
| New feature? | [yes]
| BC breaks? | [no]
| Deprecations? | [no]
| Tests pass? | [yes]
| Fixed tickets | [no]
| License | MIT
| Doc PR | [WIP]

I had the idea to develop this feature further to a presentation focused on the OptionsResolver component, it appeared to be a need expressed by many people.

Example of use:
$resolver->setDefaults(array(
'email' => 'default@email.com',
));

$resolver->setAllowedValues(array(
'email' => '/[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}/',
));

$resolver->resolve(array(
'email' => 'invalid@email',
));

this code will throw this exception :
The option "email" with value "invalid@email" is invalid. Accepted values must match the regular expression: "/[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}/".

Regards to all and happy feast for the end of year.