Skip to content

Commit 31a0604

Browse files
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
2 parents 320de71 + c7ccfbe commit 31a0604

File tree

8 files changed

+68
-2
lines changed

8 files changed

+68
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ CHANGELOG
1010
* made `ValidatorBuilder` final
1111
* marked `format` the default option in `DateTime` constraint
1212
* deprecated validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator`.
13-
* deprecated using the `Bic` constraint without `symfony/intl`
13+
* deprecated using the `Bic`, `Country`, `Currency`, `Language` and `Locale` constraints without `symfony/intl`
14+
* deprecated using the `Email` constraint without `egulias/email-validator`
15+
* deprecated using the `Expression` constraint without `symfony/expression-language`
1416

1517
4.1.0
1618
-----

Constraints/BicValidator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Intl\Intl;
1515
use Symfony\Component\Validator\Constraint;
1616
use Symfony\Component\Validator\ConstraintValidator;
17+
use Symfony\Component\Validator\Exception\LogicException;
1718
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
1819

1920
/**
@@ -68,11 +69,12 @@ public function validate($value, Constraint $constraint)
6869
return;
6970
}
7071

71-
// @deprecated since Symfony 4.2
72+
// @deprecated since Symfony 4.2, will throw in 5.0
7273
if (class_exists(Intl::class)) {
7374
$validCountryCode = isset(Intl::getRegionBundle()->getCountryNames()[substr($canonicalize, 4, 2)]);
7475
} else {
7576
$validCountryCode = ctype_alpha(substr($canonicalize, 4, 2));
77+
// throw new LogicException('The "symfony/intl" component is required to use the Bic constraint.');
7678
}
7779

7880
if (!$validCountryCode) {

Constraints/Country.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use Symfony\Component\Intl\Intl;
1415
use Symfony\Component\Validator\Constraint;
16+
use Symfony\Component\Validator\Exception\LogicException;
1517

1618
/**
1719
* @Annotation
@@ -28,4 +30,14 @@ class Country extends Constraint
2830
);
2931

3032
public $message = 'This value is not a valid country.';
33+
34+
public function __construct($options = null)
35+
{
36+
if (!class_exists(Intl::class)) {
37+
// throw new LogicException(sprintf('The "symfony/intl" component is required to use the "%s" constraint.', __CLASS__));
38+
@trigger_error(sprintf('Using the "%s" constraint without the "symfony/intl" component installed is deprecated since Symfony 4.2.', __CLASS__), E_USER_DEPRECATED);
39+
}
40+
41+
parent::__construct($options);
42+
}
3143
}

Constraints/Currency.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use Symfony\Component\Intl\Intl;
1415
use Symfony\Component\Validator\Constraint;
16+
use Symfony\Component\Validator\Exception\LogicException;
1517

1618
/**
1719
* @Annotation
@@ -29,4 +31,14 @@ class Currency extends Constraint
2931
);
3032

3133
public $message = 'This value is not a valid currency.';
34+
35+
public function __construct($options = null)
36+
{
37+
if (!class_exists(Intl::class)) {
38+
// throw new LogicException(sprintf('The "symfony/intl" component is required to use the "%s" constraint.', __CLASS__));
39+
@trigger_error(sprintf('Using the "%s" constraint without the "symfony/intl" component installed is deprecated since Symfony 4.2.', __CLASS__), E_USER_DEPRECATED);
40+
}
41+
42+
parent::__construct($options);
43+
}
3244
}

Constraints/Email.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use Egulias\EmailValidator\EmailValidator as StrictEmailValidator;
1415
use Symfony\Component\Validator\Constraint;
16+
use Symfony\Component\Validator\Exception\LogicException;
1517

1618
/**
1719
* @Annotation
@@ -67,5 +69,10 @@ public function __construct($options = null)
6769
}
6870

6971
parent::__construct($options);
72+
73+
if ((self::VALIDATION_MODE_STRICT === $this->mode || true === $this->strict) && !class_exists(StrictEmailValidator::class)) {
74+
// throw new LogicException(sprintf('The "egulias/email-validator" component is required to use the "%s" constraint.', __CLASS__));
75+
@trigger_error(sprintf('Using the "%s" constraint without the "egulias/email-validator" component installed is deprecated since Symfony 4.2.', __CLASS__), E_USER_DEPRECATED);
76+
}
7077
}
7178
}

Constraints/Expression.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
1415
use Symfony\Component\Validator\Constraint;
16+
use Symfony\Component\Validator\Exception\LogicException;
1517

1618
/**
1719
* @Annotation
@@ -32,6 +34,16 @@ class Expression extends Constraint
3234
public $expression;
3335
public $values = array();
3436

37+
public function __construct($options = null)
38+
{
39+
if (!class_exists(ExpressionLanguage::class)) {
40+
// throw new LogicException(sprintf('The "symfony/expression-language" component is required to use the "%s" constraint.', __CLASS__));
41+
@trigger_error(sprintf('Using the "%s" constraint without the "symfony/expression-language" component installed is deprecated since Symfony 4.2.', __CLASS__), E_USER_DEPRECATED);
42+
}
43+
44+
parent::__construct($options);
45+
}
46+
3547
/**
3648
* {@inheritdoc}
3749
*/

Constraints/Language.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use Symfony\Component\Intl\Intl;
1415
use Symfony\Component\Validator\Constraint;
16+
use Symfony\Component\Validator\Exception\LogicException;
1517

1618
/**
1719
* @Annotation
@@ -28,4 +30,14 @@ class Language extends Constraint
2830
);
2931

3032
public $message = 'This value is not a valid language.';
33+
34+
public function __construct($options = null)
35+
{
36+
if (!class_exists(Intl::class)) {
37+
// throw new LogicException(sprintf('The "symfony/intl" component is required to use the "%s" constraint.', __CLASS__));
38+
@trigger_error(sprintf('Using the "%s" constraint without the "symfony/intl" component installed is deprecated since Symfony 4.2.', __CLASS__), E_USER_DEPRECATED);
39+
}
40+
41+
parent::__construct($options);
42+
}
3143
}

Constraints/Locale.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use Symfony\Component\Intl\Intl;
1415
use Symfony\Component\Validator\Constraint;
16+
use Symfony\Component\Validator\Exception\LogicException;
1517

1618
/**
1719
* @Annotation
@@ -36,6 +38,11 @@ public function __construct($options = null)
3638
@trigger_error('The "canonicalize" option with value "false" is deprecated since Symfony 4.1, set it to "true" instead.', E_USER_DEPRECATED);
3739
}
3840

41+
if (!class_exists(Intl::class)) {
42+
// throw new LogicException(sprintf('The "symfony/intl" component is required to use the "%s" constraint.', __CLASS__));
43+
@trigger_error(sprintf('Using the "%s" constraint without the "symfony/intl" component installed is deprecated since Symfony 4.2.', __CLASS__), E_USER_DEPRECATED);
44+
}
45+
3946
parent::__construct($options);
4047
}
4148
}

0 commit comments

Comments
 (0)