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

Skip to content

Commit b2d2f63

Browse files
author
Robin Chalas
committed
[Validator] Add BC layer covering BicValidator without Intl
1 parent e95ea81 commit b2d2f63

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

UPGRADE-4.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,4 @@ Validator
206206
* The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead
207207
* The `ValidatorBuilderInterface` has been deprecated and `ValidatorBuilder` made final
208208
* Deprecated validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator`. Use `Type` instead or remove the constraint if the underlying model is type hinted to `\DateTimeInterface` already.
209+
* Using the `Bic` constraint without `symfony/intl` is deprecated

UPGRADE-5.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ Validator
191191
* The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead
192192
* The `ValidatorBuilderInterface` has been removed and `ValidatorBuilder` is now final
193193
* Removed support for validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator`. Use `Type` instead or remove the constraint if the underlying model is type hinted to `\DateTimeInterface` already.
194+
* The `symfony/intl` component is now required for using the `Bic` constraint
194195

195196
Workflow
196197
--------

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\Intl\Intl;
1515
use Symfony\Component\Validator\Constraint;
1616
use Symfony\Component\Validator\ConstraintValidator;
17-
use Symfony\Component\Validator\Exception\LogicException;
1817
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
1918

2019
/**
@@ -69,13 +68,16 @@ public function validate($value, Constraint $constraint)
6968
return;
7069
}
7170

71+
// @deprecated since Symfony 4.2, will throw a LogicException in 5.0
7272
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)]);
7477
}
7578

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) {
7981
$this->context->buildViolation($constraint->message)
8082
->setParameter('{{ value }}', $this->formatValue($value))
8183
->setCode(Bic::INVALID_COUNTRY_CODE_ERROR)

0 commit comments

Comments
 (0)