diff --git a/UPGRADE-4.2.md b/UPGRADE-4.2.md index fbc956265d6c..539df93720a6 100644 --- a/UPGRADE-4.2.md +++ b/UPGRADE-4.2.md @@ -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 diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 5bebd035cc48..237e3f7e4d73 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -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 -------- diff --git a/src/Symfony/Component/Validator/CHANGELOG.md b/src/Symfony/Component/Validator/CHANGELOG.md index ac98f581b360..e69e0e932f6c 100644 --- a/src/Symfony/Component/Validator/CHANGELOG.md +++ b/src/Symfony/Component/Validator/CHANGELOG.md @@ -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 ----- diff --git a/src/Symfony/Component/Validator/Constraints/BicValidator.php b/src/Symfony/Component/Validator/Constraints/BicValidator.php index 2d0a450e8645..89077db68038 100644 --- a/src/Symfony/Component/Validator/Constraints/BicValidator.php +++ b/src/Symfony/Component/Validator/Constraints/BicValidator.php @@ -14,6 +14,7 @@ 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 @@ public function validate($value, Constraint $constraint) 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) { diff --git a/src/Symfony/Component/Validator/Constraints/Country.php b/src/Symfony/Component/Validator/Constraints/Country.php index 1b76570a8c5f..435d12cd41b5 100644 --- a/src/Symfony/Component/Validator/Constraints/Country.php +++ b/src/Symfony/Component/Validator/Constraints/Country.php @@ -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); + } } diff --git a/src/Symfony/Component/Validator/Constraints/Currency.php b/src/Symfony/Component/Validator/Constraints/Currency.php index d28f94cb66a7..28e546d6b9bb 100644 --- a/src/Symfony/Component/Validator/Constraints/Currency.php +++ b/src/Symfony/Component/Validator/Constraints/Currency.php @@ -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); + } } diff --git a/src/Symfony/Component/Validator/Constraints/Email.php b/src/Symfony/Component/Validator/Constraints/Email.php index ba588a4c1cf0..b98b00a90567 100644 --- a/src/Symfony/Component/Validator/Constraints/Email.php +++ b/src/Symfony/Component/Validator/Constraints/Email.php @@ -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 @@ public function __construct($options = null) } 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); + } } } diff --git a/src/Symfony/Component/Validator/Constraints/Expression.php b/src/Symfony/Component/Validator/Constraints/Expression.php index b8c3cb71df69..e48da1601090 100644 --- a/src/Symfony/Component/Validator/Constraints/Expression.php +++ b/src/Symfony/Component/Validator/Constraints/Expression.php @@ -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} */ diff --git a/src/Symfony/Component/Validator/Constraints/Language.php b/src/Symfony/Component/Validator/Constraints/Language.php index 0e676b7aabcd..f24d1e0b9725 100644 --- a/src/Symfony/Component/Validator/Constraints/Language.php +++ b/src/Symfony/Component/Validator/Constraints/Language.php @@ -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); + } } diff --git a/src/Symfony/Component/Validator/Constraints/Locale.php b/src/Symfony/Component/Validator/Constraints/Locale.php index 076850b1f112..e2c780c15d95 100644 --- a/src/Symfony/Component/Validator/Constraints/Locale.php +++ b/src/Symfony/Component/Validator/Constraints/Locale.php @@ -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 @@ public function __construct($options = null) @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); } }