Skip to content

Commit

Permalink
minor #31680 [Validator] Remove fallback dependency checks (ro0NL)
Browse files Browse the repository at this point in the history
This PR was merged into the 5.0-dev branch.

Discussion
----------

[Validator] Remove fallback dependency checks

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

See #28644

Commits
-------

aa84cfd     [Validator] Remove fallback dependency checks
  • Loading branch information
nicolas-grekas committed May 29, 2019
2 parents 52756a5 + aa84cfd commit 03797a1
Show file tree
Hide file tree
Showing 14 changed files with 8 additions and 52 deletions.
3 changes: 1 addition & 2 deletions src/Symfony/Component/Validator/Constraints/Bic.php
Expand Up @@ -48,8 +48,7 @@ class Bic extends Constraint
public function __construct($options = null)
{
if (!class_exists(Countries::class)) {
// throw new LogicException('The Intl component is required to use the Bic constraint. Try running "composer require symfony/intl".');
@trigger_error(sprintf('Using the "%s" constraint without the "symfony/intl" component installed is deprecated since Symfony 4.2.', __CLASS__), E_USER_DEPRECATED);
throw new LogicException('The Intl component is required to use the Bic constraint. Try running "composer require symfony/intl".');
}

if (isset($options['iban']) && isset($options['ibanPropertyPath'])) {
Expand Down
10 changes: 1 addition & 9 deletions src/Symfony/Component/Validator/Constraints/BicValidator.php
Expand Up @@ -104,15 +104,7 @@ public function validate($value, Constraint $constraint)
return;
}

// @deprecated since Symfony 4.2, will throw in 5.0
if (class_exists(Countries::class)) {
$validCountryCode = Countries::exists(substr($canonicalize, 4, 2));
} else {
$validCountryCode = ctype_alpha(substr($canonicalize, 4, 2));
// throw new LogicException('The Intl component is required to use the Bic constraint. Try running "composer require symfony/intl".');
}

if (!$validCountryCode) {
if (!Countries::exists(substr($canonicalize, 4, 2))) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Bic::INVALID_COUNTRY_CODE_ERROR)
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Validator/Constraints/Country.php
Expand Up @@ -34,8 +34,7 @@ class Country extends Constraint
public function __construct($options = null)
{
if (!class_exists(Countries::class)) {
// throw new LogicException('The Intl component is required to use the Country constraint. Try running "composer require symfony/intl".');
@trigger_error(sprintf('Using the "%s" constraint without the "symfony/intl" component installed is deprecated since Symfony 4.2.', __CLASS__), E_USER_DEPRECATED);
throw new LogicException('The Intl component is required to use the Country constraint. Try running "composer require symfony/intl".');
}

parent::__construct($options);
Expand Down
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\Intl\Countries;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\LogicException;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;

Expand Down Expand Up @@ -42,10 +41,6 @@ public function validate($value, Constraint $constraint)
throw new UnexpectedValueException($value, 'string');
}

if (!class_exists(Countries::class)) {
throw new LogicException('The Intl component is required to use the Country constraint. Try running "composer require symfony/intl".');
}

$value = (string) $value;

if (!Countries::exists($value)) {
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Validator/Constraints/Currency.php
Expand Up @@ -35,8 +35,7 @@ class Currency extends Constraint
public function __construct($options = null)
{
if (!class_exists(Currencies::class)) {
// throw new LogicException('The Intl component is required to use the Currency constraint. Try running "composer require symfony/intl".');
@trigger_error(sprintf('Using the "%s" constraint without the "symfony/intl" component installed is deprecated since Symfony 4.2.', __CLASS__), E_USER_DEPRECATED);
throw new LogicException('The Intl component is required to use the Currency constraint. Try running "composer require symfony/intl".');
}

parent::__construct($options);
Expand Down
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\Intl\Currencies;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\LogicException;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;

Expand Down Expand Up @@ -43,10 +42,6 @@ public function validate($value, Constraint $constraint)
throw new UnexpectedValueException($value, 'string');
}

if (!class_exists(Currencies::class)) {
throw new LogicException('The Intl component is required to use the Currency constraint. Try running "composer require symfony/intl".');
}

$value = (string) $value;

if (!Currencies::exists($value)) {
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Validator/Constraints/Email.php
Expand Up @@ -97,8 +97,7 @@ 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 in strict mode.', __CLASS__));
@trigger_error(sprintf('Using the "%s" constraint in strict mode without the "egulias/email-validator" component installed is deprecated since Symfony 4.2.', __CLASS__), E_USER_DEPRECATED);
throw new LogicException(sprintf('The "egulias/email-validator" component is required to use the "%s" constraint in strict mode.', __CLASS__));
}

if (null !== $this->normalizer && !\is_callable($this->normalizer)) {
Expand Down
Expand Up @@ -15,7 +15,6 @@
use Egulias\EmailValidator\Validation\NoRFCWarningsValidation;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\LogicException;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;

Expand Down Expand Up @@ -104,10 +103,6 @@ public function validate($value, Constraint $constraint)
}

if (Email::VALIDATION_MODE_STRICT === $constraint->mode) {
if (!class_exists('\Egulias\EmailValidator\EmailValidator')) {
throw new LogicException('Strict email validation requires egulias/email-validator ~1.2|~2.0');
}

$strictValidator = new \Egulias\EmailValidator\EmailValidator();

if (interface_exists(EmailValidation::class) && !$strictValidator->isValid($value, new NoRFCWarningsValidation())) {
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Validator/Constraints/Expression.php
Expand Up @@ -37,8 +37,7 @@ class Expression extends Constraint
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);
throw new LogicException(sprintf('The "symfony/expression-language" component is required to use the "%s" constraint.', __CLASS__));
}

parent::__construct($options);
Expand Down
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\LogicException;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;

/**
Expand Down Expand Up @@ -54,9 +53,6 @@ public function validate($value, Constraint $constraint)
private function getExpressionLanguage()
{
if (null === $this->expressionLanguage) {
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
throw new LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
}
$this->expressionLanguage = new ExpressionLanguage();
}

Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Validator/Constraints/Language.php
Expand Up @@ -34,8 +34,7 @@ class Language extends Constraint
public function __construct($options = null)
{
if (!class_exists(Languages::class)) {
// throw new LogicException('The Intl component is required to use the Language constraint. Try running "composer require symfony/intl".');
@trigger_error(sprintf('Using the "%s" constraint without the "symfony/intl" component installed is deprecated since Symfony 4.2.', __CLASS__), E_USER_DEPRECATED);
throw new LogicException('The Intl component is required to use the Language constraint. Try running "composer require symfony/intl".');
}

parent::__construct($options);
Expand Down
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\Intl\Languages;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\LogicException;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;

Expand Down Expand Up @@ -42,10 +41,6 @@ public function validate($value, Constraint $constraint)
throw new UnexpectedValueException($value, 'string');
}

if (!class_exists(Languages::class)) {
throw new LogicException('The Intl component is required to use the Language constraint. Try running "composer require symfony/intl".');
}

$value = (string) $value;

if (!Languages::exists($value)) {
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Validator/Constraints/Locale.php
Expand Up @@ -39,8 +39,7 @@ public function __construct($options = null)
}

if (!class_exists(Locales::class)) {
// throw new LogicException('The Intl component is required to use the Locale constraint. Try running "composer require symfony/intl".');
@trigger_error(sprintf('Using the "%s" constraint without the "symfony/intl" component installed is deprecated since Symfony 4.2.', __CLASS__), E_USER_DEPRECATED);
throw new LogicException('The Intl component is required to use the Locale constraint. Try running "composer require symfony/intl".');
}

parent::__construct($options);
Expand Down
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\Intl\Locales;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\LogicException;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;

Expand Down Expand Up @@ -42,10 +41,6 @@ public function validate($value, Constraint $constraint)
throw new UnexpectedValueException($value, 'string');
}

if (!class_exists(Locales::class)) {
throw new LogicException('The Intl component is required to use the Locale constraint. Try running "composer require symfony/intl".');
}

$inputValue = (string) $value;
$value = $inputValue;
if ($constraint->canonicalize) {
Expand Down

0 comments on commit 03797a1

Please sign in to comment.