Use Symfony\Component\Intl\Locale
instead of \Locale
+ read aliases from bundle only if it is required
This commit is contained in:
parent
dfa7bb44ac
commit
63497e1761
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\Validator\Constraints;
|
namespace Symfony\Component\Validator\Constraints;
|
||||||
|
|
||||||
use Symfony\Component\Intl\Intl;
|
use Symfony\Component\Intl\Intl;
|
||||||
|
use Symfony\Component\Intl\Locale as IntlLocale;
|
||||||
use Symfony\Component\Validator\Constraint;
|
use Symfony\Component\Validator\Constraint;
|
||||||
use Symfony\Component\Validator\ConstraintValidator;
|
use Symfony\Component\Validator\ConstraintValidator;
|
||||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||||
@ -42,12 +43,12 @@ class LocaleValidator extends ConstraintValidator
|
|||||||
|
|
||||||
$value = (string) $value;
|
$value = (string) $value;
|
||||||
if ($constraint->canonicalize) {
|
if ($constraint->canonicalize) {
|
||||||
$value = \Locale::canonicalize($value);
|
$value = IntlLocale::canonicalize($value);
|
||||||
}
|
}
|
||||||
$locales = Intl::getLocaleBundle()->getLocaleNames();
|
$localeBundle = Intl::getLocaleBundle();
|
||||||
$aliases = Intl::getLocaleBundle()->getAliases();
|
$locales = $localeBundle->getLocaleNames();
|
||||||
|
|
||||||
if (!isset($locales[$value]) && !in_array($value, $aliases)) {
|
if (!isset($locales[$value]) && !in_array($value, $localeBundle->getAliases(), true)) {
|
||||||
$this->context->buildViolation($constraint->message)
|
$this->context->buildViolation($constraint->message)
|
||||||
->setParameter('{{ value }}', $this->formatValue($value))
|
->setParameter('{{ value }}', $this->formatValue($value))
|
||||||
->setCode(Locale::NO_SUCH_LOCALE_ERROR)
|
->setCode(Locale::NO_SUCH_LOCALE_ERROR)
|
||||||
|
Reference in New Issue
Block a user