|
14 | 14 | use Symfony\Component\Intl\Intl;
|
15 | 15 | use Symfony\Component\Validator\Constraint;
|
16 | 16 | use Symfony\Component\Validator\ConstraintValidator;
|
17 |
| -use Symfony\Component\Validator\Exception\LogicException; |
18 | 17 | use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
19 | 18 |
|
20 | 19 | /**
|
@@ -69,13 +68,16 @@ public function validate($value, Constraint $constraint)
|
69 | 68 | return;
|
70 | 69 | }
|
71 | 70 |
|
| 71 | + // @deprecated since Symfony 4.2, will throw a LogicException in 5.0 |
72 | 72 | if (!class_exists(Intl::class)) {
|
73 |
| - throw new LogicException('The "symfony/intl" component is required to use the Bic constraint.'); |
| 73 | + @trigger_error('Using the Bic constraint without the "symfony/intl" component installed is deprecated since Symfony 4.2.', E_USER_DEPRECATED); |
| 74 | + $invalidCountryCode = !ctype_alpha(substr($canonicalize, 4, 2)); |
| 75 | + } else { |
| 76 | + $invalidCountryCode = !isset(Intl::getRegionBundle()->getCountryNames()[substr($canonicalize, 4, 2)]); |
74 | 77 | }
|
75 | 78 |
|
76 |
| - // next 2 letters must be alphabetic (country code) |
77 |
| - $countries = Intl::getRegionBundle()->getCountryNames(); |
78 |
| - if (!isset($countries[substr($canonicalize, 4, 2)])) { |
| 79 | + // next 2 letters must be a valid country code |
| 80 | + if ($invalidCountryCode) { |
79 | 81 | $this->context->buildViolation($constraint->message)
|
80 | 82 | ->setParameter('{{ value }}', $this->formatValue($value))
|
81 | 83 | ->setCode(Bic::INVALID_COUNTRY_CODE_ERROR)
|
|
0 commit comments