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 09e8371

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

File tree

5 files changed

+21
-6
lines changed
Filter options

5 files changed

+21
-6
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/Bic.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/Bic.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use Symfony\Component\Intl\Intl;
1415
use Symfony\Component\Validator\Constraint;
1516

1617
/**
@@ -36,4 +37,15 @@ class Bic extends Constraint
3637
);
3738

3839
public $message = 'This is not a valid Business Identifier Code (BIC).';
40+
41+
public function __construct($options = null)
42+
{
43+
// @deprecated since Symfony 4.2
44+
// throw new LoginException(sprintf('The "symfony/intl" component is required to use the "%s" constraint.', __CLASS__));
45+
if (!class_exists(Intl::class)) {
46+
@trigger_error(sprintf('Using the "%s" constraint without the "symfony/intl" component installed is deprecated since Symfony 4.2.', __CLASS__), E_USER_DEPRECATED);
47+
}
48+
49+
parent::__construct($options);
50+
}
3951
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/BicValidator.php
+6-6Lines changed: 6 additions & 6 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,14 @@ public function validate($value, Constraint $constraint)
6968
return;
7069
}
7170

72-
if (!class_exists(Intl::class)) {
73-
throw new LogicException('The "symfony/intl" component is required to use the Bic constraint.');
71+
// @deprecated since Symfony 4.2
72+
if (class_exists(Intl::class)) {
73+
$validCountryCode = isset(Intl::getRegionBundle()->getCountryNames()[substr($canonicalize, 4, 2)]);
74+
} else {
75+
$validCountryCode = ctype_alpha(substr($canonicalize, 4, 2));
7476
}
7577

76-
// next 2 letters must be alphabetic (country code)
77-
$countries = Intl::getRegionBundle()->getCountryNames();
78-
if (!isset($countries[substr($canonicalize, 4, 2)])) {
78+
if (!$validCountryCode) {
7979
$this->context->buildViolation($constraint->message)
8080
->setParameter('{{ value }}', $this->formatValue($value))
8181
->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.