minor #28606 [Validator] Add BC layer covering BicValidator without Intl (chalasr)
This PR was merged into the 4.2-dev branch.
Discussion
----------
[Validator] Add BC layer covering BicValidator without Intl
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | yes
| Tests pass? | yes
| Fixed tickets | https://github.com/symfony/symfony/pull/28473#pullrequestreview-158620738
| License | MIT
| Doc PR | n/a
Commits
-------
10b8a5f041
[Validator] Add BC layer covering BicValidator without Intl
This commit is contained in:
commit
91add60d47
@ -216,3 +216,4 @@ Validator
|
|||||||
* The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead
|
* The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead
|
||||||
* The `ValidatorBuilderInterface` has been deprecated and `ValidatorBuilder` made final
|
* The `ValidatorBuilderInterface` has been deprecated and `ValidatorBuilder` made final
|
||||||
* 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.
|
* 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.
|
||||||
|
* Using the `Bic` constraint without `symfony/intl` is deprecated
|
||||||
|
@ -199,6 +199,7 @@ Validator
|
|||||||
* The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead
|
* The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead
|
||||||
* The `ValidatorBuilderInterface` has been removed and `ValidatorBuilder` is now final
|
* The `ValidatorBuilderInterface` has been removed and `ValidatorBuilder` is now final
|
||||||
* 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.
|
* 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.
|
||||||
|
* The `symfony/intl` component is now required for using the `Bic` constraint
|
||||||
|
|
||||||
Workflow
|
Workflow
|
||||||
--------
|
--------
|
||||||
|
@ -10,6 +10,7 @@ CHANGELOG
|
|||||||
* made `ValidatorBuilder` final
|
* made `ValidatorBuilder` final
|
||||||
* marked `format` the default option in `DateTime` constraint
|
* marked `format` the default option in `DateTime` constraint
|
||||||
* deprecated validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator`.
|
* deprecated validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator`.
|
||||||
|
* deprecated using the `Bic` constraint without `symfony/intl`
|
||||||
|
|
||||||
4.1.0
|
4.1.0
|
||||||
-----
|
-----
|
||||||
|
@ -11,7 +11,9 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Validator\Constraints;
|
namespace Symfony\Component\Validator\Constraints;
|
||||||
|
|
||||||
|
use Symfony\Component\Intl\Intl;
|
||||||
use Symfony\Component\Validator\Constraint;
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
use Symfony\Component\Validator\Exception\LogicException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Annotation
|
* @Annotation
|
||||||
@ -36,4 +38,14 @@ class Bic extends Constraint
|
|||||||
);
|
);
|
||||||
|
|
||||||
public $message = 'This is not a valid Business Identifier Code (BIC).';
|
public $message = 'This is not a valid Business Identifier Code (BIC).';
|
||||||
|
|
||||||
|
public function __construct($options = null)
|
||||||
|
{
|
||||||
|
if (!class_exists(Intl::class)) {
|
||||||
|
// throw new LogicException(sprintf('The "symfony/intl" component is required to use the "%s" constraint.', __CLASS__));
|
||||||
|
@trigger_error(sprintf('Using the "%s" constraint without the "symfony/intl" component installed is deprecated since Symfony 4.2.', __CLASS__), E_USER_DEPRECATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::__construct($options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ namespace Symfony\Component\Validator\Constraints;
|
|||||||
use Symfony\Component\Intl\Intl;
|
use Symfony\Component\Intl\Intl;
|
||||||
use Symfony\Component\Validator\Constraint;
|
use Symfony\Component\Validator\Constraint;
|
||||||
use Symfony\Component\Validator\ConstraintValidator;
|
use Symfony\Component\Validator\ConstraintValidator;
|
||||||
use Symfony\Component\Validator\Exception\LogicException;
|
|
||||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,13 +68,14 @@ class BicValidator extends ConstraintValidator
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!class_exists(Intl::class)) {
|
// @deprecated since Symfony 4.2
|
||||||
throw new LogicException('The "symfony/intl" component is required to use the Bic constraint.');
|
if (class_exists(Intl::class)) {
|
||||||
|
$validCountryCode = isset(Intl::getRegionBundle()->getCountryNames()[substr($canonicalize, 4, 2)]);
|
||||||
|
} else {
|
||||||
|
$validCountryCode = ctype_alpha(substr($canonicalize, 4, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// next 2 letters must be alphabetic (country code)
|
if (!$validCountryCode) {
|
||||||
$countries = Intl::getRegionBundle()->getCountryNames();
|
|
||||||
if (!isset($countries[substr($canonicalize, 4, 2)])) {
|
|
||||||
$this->context->buildViolation($constraint->message)
|
$this->context->buildViolation($constraint->message)
|
||||||
->setParameter('{{ value }}', $this->formatValue($value))
|
->setParameter('{{ value }}', $this->formatValue($value))
|
||||||
->setCode(Bic::INVALID_COUNTRY_CODE_ERROR)
|
->setCode(Bic::INVALID_COUNTRY_CODE_ERROR)
|
||||||
|
Reference in New Issue
Block a user