[Validator] Pre-check constraint validator dependencies
This commit is contained in:
parent
d1fd4325ea
commit
0544985934
@ -216,4 +216,6 @@ Validator
|
||||
* The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead
|
||||
* 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.
|
||||
* Using the `Bic` constraint without `symfony/intl` is deprecated
|
||||
* Using the `Bic`, `Country`, `Currency`, `Language` and `Locale` constraints without `symfony/intl` is deprecated
|
||||
* Using the `Email` constraint without `egulias/email-validator` is deprecated
|
||||
* Using the `Expression` constraint without `symfony/expression-language` is deprecated
|
||||
|
@ -199,7 +199,9 @@ Validator
|
||||
* 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
|
||||
* 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
|
||||
* The `symfony/intl` component is now required for using the `Bic`, `Country`, `Currency`, `Language` and `Locale` constraints
|
||||
* The `egulias/email-validator` component is now required for using the `Email` constraint
|
||||
* The `symfony/expression-language` component is now required for using the `Expression` constraint
|
||||
|
||||
Workflow
|
||||
--------
|
||||
|
@ -10,7 +10,9 @@ CHANGELOG
|
||||
* made `ValidatorBuilder` final
|
||||
* marked `format` the default option in `DateTime` constraint
|
||||
* deprecated validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator`.
|
||||
* deprecated using the `Bic` constraint without `symfony/intl`
|
||||
* deprecated using the `Bic`, `Country`, `Currency`, `Language` and `Locale` constraints without `symfony/intl`
|
||||
* deprecated using the `Email` constraint without `egulias/email-validator`
|
||||
* deprecated using the `Expression` constraint without `symfony/expression-language`
|
||||
|
||||
4.1.0
|
||||
-----
|
||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Component\Intl\Intl;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\LogicException;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
||||
@ -68,11 +69,12 @@ class BicValidator extends ConstraintValidator
|
||||
return;
|
||||
}
|
||||
|
||||
// @deprecated since Symfony 4.2
|
||||
// @deprecated since Symfony 4.2, will throw in 5.0
|
||||
if (class_exists(Intl::class)) {
|
||||
$validCountryCode = isset(Intl::getRegionBundle()->getCountryNames()[substr($canonicalize, 4, 2)]);
|
||||
} else {
|
||||
$validCountryCode = ctype_alpha(substr($canonicalize, 4, 2));
|
||||
// throw new LogicException('The "symfony/intl" component is required to use the Bic constraint.');
|
||||
}
|
||||
|
||||
if (!$validCountryCode) {
|
||||
|
@ -11,7 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Intl\Intl;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Exception\LogicException;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
@ -28,4 +30,14 @@ class Country extends Constraint
|
||||
);
|
||||
|
||||
public $message = 'This value is not a valid country.';
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Intl\Intl;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Exception\LogicException;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
@ -29,4 +31,14 @@ class Currency extends Constraint
|
||||
);
|
||||
|
||||
public $message = 'This value is not a valid currency.';
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Egulias\EmailValidator\EmailValidator as StrictEmailValidator;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Exception\LogicException;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
@ -67,5 +69,10 @@ class Email extends Constraint
|
||||
}
|
||||
|
||||
parent::__construct($options);
|
||||
|
||||
if ((self::VALIDATION_MODE_STRICT === $this->mode || true === $this->strict) && !class_exists(StrictEmailValidator::class)) {
|
||||
// throw new LogicException(sprintf('The "egulias/email-validator" component is required to use the "%s" constraint.', __CLASS__));
|
||||
@trigger_error(sprintf('Using the "%s" constraint without the "egulias/email-validator" component installed is deprecated since Symfony 4.2.', __CLASS__), E_USER_DEPRECATED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Exception\LogicException;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
@ -32,6 +34,16 @@ class Expression extends Constraint
|
||||
public $expression;
|
||||
public $values = array();
|
||||
|
||||
public function __construct($options = null)
|
||||
{
|
||||
if (!class_exists(ExpressionLanguage::class)) {
|
||||
// throw new LogicException(sprintf('The "symfony/expression-language" component is required to use the "%s" constraint.', __CLASS__));
|
||||
@trigger_error(sprintf('Using the "%s" constraint without the "symfony/expression-language" component installed is deprecated since Symfony 4.2.', __CLASS__), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -11,7 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Intl\Intl;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Exception\LogicException;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
@ -28,4 +30,14 @@ class Language extends Constraint
|
||||
);
|
||||
|
||||
public $message = 'This value is not a valid language.';
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Intl\Intl;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Exception\LogicException;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
@ -36,6 +38,11 @@ class Locale extends Constraint
|
||||
@trigger_error('The "canonicalize" option with value "false" is deprecated since Symfony 4.1, set it to "true" instead.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user