Skip to content

Commit 63497e1

Browse files
committed
Use Symfony\Component\Intl\Locale instead of \Locale + read aliases from bundle only if it is required
1 parent dfa7bb4 commit 63497e1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Symfony/Component/Validator/Constraints/LocaleValidator.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Validator\Constraints;
1313

1414
use Symfony\Component\Intl\Intl;
15+
use Symfony\Component\Intl\Locale as IntlLocale;
1516
use Symfony\Component\Validator\Constraint;
1617
use Symfony\Component\Validator\ConstraintValidator;
1718
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
@@ -42,12 +43,12 @@ public function validate($value, Constraint $constraint)
4243

4344
$value = (string) $value;
4445
if ($constraint->canonicalize) {
45-
$value = \Locale::canonicalize($value);
46+
$value = IntlLocale::canonicalize($value);
4647
}
47-
$locales = Intl::getLocaleBundle()->getLocaleNames();
48-
$aliases = Intl::getLocaleBundle()->getAliases();
48+
$localeBundle = Intl::getLocaleBundle();
49+
$locales = $localeBundle->getLocaleNames();
4950

50-
if (!isset($locales[$value]) && !in_array($value, $aliases)) {
51+
if (!isset($locales[$value]) && !in_array($value, $localeBundle->getAliases(), true)) {
5152
$this->context->buildViolation($constraint->message)
5253
->setParameter('{{ value }}', $this->formatValue($value))
5354
->setCode(Locale::NO_SUCH_LOCALE_ERROR)

0 commit comments

Comments
 (0)