Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ec2219

Browse files
committed
minor #26069 [LocaleValidator] Use Symfony\Component\Intl\Locale instead of \Locale + read aliases from bundle only if it is required (phansys)
This PR was merged into the 4.1-dev branch. Discussion ---------- [LocaleValidator] Use `Symfony\Component\Intl\Locale` instead of `\Locale` + read aliases from bundle only if it is required |Q |A | |--- |--- | |Branch |master| |Bug fix? |no | |New feature? |no | |BC breaks? |no | |Deprecations?|no | |Tests pass? |yes | |Fixed tickets|n/a | |License |MIT | |Doc PR |n/a | Commits ------- 63497e1 Use `Symfony\Component\Intl\Locale` instead of `\Locale` + read aliases from bundle only if it is required
2 parents 101a795 + 63497e1 commit 1ec2219

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)