feature #28644 [Validator] Pre-check constraint validator dependencies (ro0NL)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Validator] Pre-check constraint validator dependencies

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | yes
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #25865
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->

Commits
-------

0544985934 [Validator] Pre-check constraint validator dependencies
This commit is contained in:
Nicolas Grekas 2018-10-03 08:20:15 +02:00
commit 3b604ffe94
10 changed files with 74 additions and 4 deletions

View File

@ -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

View File

@ -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
--------

View File

@ -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
-----

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}
}

View File

@ -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}
*/

View File

@ -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);
}
}

View File

@ -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);
}
}