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

This commit is contained in:
Jakub Zalas 2016-03-07 16:40:05 +00:00
parent 6d5dbf7a75
commit fbb12d89d1
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"
},