symfony/symfony — pull request #13069 by SofHad (2014-12-21 20:30:54+00:00)
Title: [OptionsResolver] Added Ability to filter by regex the allowed values

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

- [ ] document the BC breaks

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}/".