bug #18049 [Validator] Fix the locale validator so it treats a locale alias as a valid locale (jakzal)

This PR was merged into the 2.3 branch.

Discussion
----------

[Validator] Fix the locale validator so it treats a locale alias as a valid locale

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

Commits
-------

fbb12d8 [Validator] Fix the locale validator so it treats a locale alias as a valid locale
This commit is contained in:
Fabien Potencier 2016-03-08 09:19:01 +01:00
commit 35666f05f7
3 changed files with 4 additions and 2 deletions

View File

@ -38,8 +38,9 @@ class LocaleValidator extends ConstraintValidator
$value = (string) $value;
$locales = Intl::getLocaleBundle()->getLocaleNames();
$aliases = Intl::getLocaleBundle()->getAliases();
if (!isset($locales[$value])) {
if (!isset($locales[$value]) && !in_array($value, $aliases)) {
$this->context->addViolation($constraint->message, array(
'{{ value }}' => $this->formatValue($value),
));

View File

@ -61,6 +61,7 @@ class LocaleValidatorTest extends AbstractConstraintValidatorTest
array('pt'),
array('pt_PT'),
array('zh_Hans'),
array('fil_PH'),
);
}

View File

@ -22,7 +22,7 @@
"require-dev": {
"doctrine/common": "~2.3",
"symfony/http-foundation": "~2.1",
"symfony/intl": "~2.3",
"symfony/intl": "^2.3.21",
"symfony/yaml": "~2.0,>=2.0.5",
"symfony/config": "~2.2"
},