Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b73a3d6

Browse filesBrowse files
author
Robin Chalas
committed
[Validator] Add BC layer covering BicValidator without Intl
1 parent e95ea81 commit b73a3d6
Copy full SHA for b73a3d6

File tree

4 files changed

+9
-5
lines changed
Filter options

4 files changed

+9
-5
lines changed

‎UPGRADE-4.2.md

Copy file name to clipboardExpand all lines: UPGRADE-4.2.md
+1Lines 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

Copy file name to clipboardExpand all lines: UPGRADE-5.0.md
+1Lines 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/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
* made `ValidatorBuilder` final
1111
* marked `format` the default option in `DateTime` constraint
1212
* deprecated validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator`.
13+
* deprecated using the `Bic` constraint without `symfony/intl`
1314

1415
4.1.0
1516
-----

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/BicValidator.php
+6-5Lines changed: 6 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,15 @@ 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+
if ($invalidCountryCode) {
7980
$this->context->buildViolation($constraint->message)
8081
->setParameter('{{ value }}', $this->formatValue($value))
8182
->setCode(Bic::INVALID_COUNTRY_CODE_ERROR)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.