8000 [Validator] remove deprecated code paths · symfony/symfony@90bfa80 · GitHub
[go: up one dir, main page]

Skip to content

Commit 90bfa80

Browse files
[Validator] remove deprecated code paths
1 parent f930ed2 commit 90bfa80

17 files changed

+95
-732
lines changed

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ CHANGELOG
55
-----
66

77
* removed the `checkDNS` and `dnsMessage` options of the `Url` constraint
8+
* removed the `checkMX`, `checkHost` and `strict` options of the `Email` constraint
89
* removed support for validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator`
910
* removed support for using the `Bic`, `Country`, `Currency`, `Language` and `Locale` constraints without `symfony/intl`
1011
* removed support for using the `Email` constraint without `egulias/email-validator`
1112
* removed support for using the `Expression` constraint without `symfony/expression-language`
13+
* changed default value of `canonicalize` option of `Locale` constraint to `true`
14+
* removed `ValidatorBuilderInterface`
1215

1316
4.4.0
1417
-----

src/Symfony/Component/Validator/Constraints/Email.php

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,8 @@ class Email extends Constraint
3030

3131
const INVALID_FORMAT_ERROR = 'bd79c0ab-ddba-46cc-a703-a7a4b08de310';
3232

33-
/**
34-
* @deprecated since Symfony 4.2.
35-
*/
36-
const MX_CHECK_FAILED_ERROR = 'bf447c1c-0266-4e10-9c6c-573df282e413';
37-
38-
/**
39-
* @deprecated since Symfony 4.2.
40-
*/
41-
const HOST_CHECK_FAILED_ERROR = '7da53a8b-56f3-4288-bb3e-ee9ede4ef9a1';
42-
4333
protected static $errorNames = [
4434
self::INVALID_FORMAT_ERROR => 'STRICT_CHECK_FAILED_ERROR',
45-
self::MX_CHECK_FAILED_ERROR => 'MX_CHECK_FAILED_ERROR',
46-
self::HOST_CHECK_FAILED_ERROR => 'HOST_CHECK_FAILED_ERROR',
4735
];
4836

4937
/**
@@ -58,45 +46,18 @@ class Email extends Constraint
5846
];
5947

6048
public $message = 'This value is not a valid email address.';
61-
62-
/**
63-
* @deprecated since Symfony 4.2.
64-
*/
65-
public $checkMX = false;
66-
67-
/**
68-
* @deprecated since Symfony 4.2.
69-
*/
70-
public $checkHost = false;
71-
72-
/**
73-
* @deprecated since Symfony 4.1, set mode to "strict" instead.
74-
*/
75-
public $strict;
7649
public $mode;
7750
public $normalizer;
7851

7952
public function __construct($options = null)
8053
{
81-
if (\is_array($options) && \array_key_exists('strict', $options)) {
82-
@trigger_error(sprintf('The "strict" property is deprecated since Symfony 4.1. Use "mode"=>"%s" instead.', self::VALIDATION_MODE_STRICT), E_USER_DEPRECATED);
83-
}
84-
85-
if (\is_array($options) && \array_key_exists('checkMX', $options)) {
86-
@trigger_error('The "checkMX" option is deprecated since Symfony 4.2.', E_USER_DEPRECATED);
87-
}
88-
89-
if (\is_array($options) && \array_key_exists('checkHost', $options)) {
90-
@trigger_error('The "checkHost" option is deprecated since Symfony 4.2.', E_USER_DEPRECATED);
91-
}
92-
9354
if (\is_array($options) && \array_key_exists('mode', $options) && !\in_array($options['mode'], self::$validationModes, true)) {
9455
throw new InvalidArgumentException('The "mode" parameter value is not valid.');
9556
}
9657

9758
parent::__construct($options);
9859

99-
if ((self::VALIDATION_MODE_STRICT === $this->mode || true === $this->strict) && !class_exists(StrictEmailValidator::class)) {
60+
if (self::VALIDATION_MODE_STRICT === $this->mode && !class_exists(StrictEmailValidator::class)) {
10061
throw new LogicException(sprintf('The "egulias/email-validator" component is required to use the "%s" constraint in strict mode.', __CLASS__));
10162
}
10263

src/Symfony/Component/Validator/Constraints/EmailValidator.php

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,18 @@
2323
*/
2424
class EmailValidator extends ConstraintValidator
2525
{
26-
/**
27-
* @internal
28-
*/
29-
const PATTERN_HTML5 = '/^[a-zA-Z0-9.!#$%&\'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/';
30-
31-
/**
32-
* @internal
33-
*/
34-
const PATTERN_LOOSE = '/^.+\@\S+\.\S+$/';
26+
private const PATTERN_HTML5 = '/^[a-zA-Z0-9.!#$%&\'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/';
27+
private const PATTERN_LOOSE = '/^.+\@\S+\.\S+$/';
3528

3629
private static $emailPatterns = [
3730
Email::VALIDATION_MODE_LOOSE => self::PATTERN_LOOSE,
3831
Email::VALIDATION_MODE_HTML5 => self::PATTERN_HTML5,
3932
];
4033

41-
/**
42-
* @var string
43-
*/
4434
private $defaultMode;
4535

46-
/**
47-
* @param string $defaultMode
48-
*/
49-
public function __construct($defaultMode = Email::VALIDATION_MODE_LOOSE)
36+
public function __construct(string $defaultMode = Email::VALIDATION_MODE_LOOSE)
5037
{
51-
if (\is_bool($defaultMode)) {
52-
@trigger_error(sprintf('Calling `new %s(%s)` is deprecated since Symfony 4.1, use `new %s("%s")` instead.', self::class, $defaultMode ? 'true' : 'false', self::class, $defaultMode ? Email::VALIDATION_MODE_STRICT : Email::VALIDATION_MODE_LOOSE), E_USER_DEPRECATED);
53-
54-
$defaultMode = $defaultMode ? Email::VALIDATION_MODE_STRICT : Email::VALIDATION_MODE_LOOSE;
55-
}
56-
5738
if (!\in_array($defaultMode, Email::$validationModes, true)) {
5839
throw new \InvalidArgumentException('The "defaultMode" parameter value is not valid.');
5940
}
@@ -84,16 +65,6 @@ public function validate($value, Constraint $constraint)
8465
$value = ($constraint->normalizer)($value);
8566
}
8667

87-
if (null !== $constraint->strict) {
88-
@trigger_error(sprintf('The %s::$strict property is deprecated since Symfony 4.1. Use %s::mode="%s" instead.', Email::class, Email::class, Email::VALIDATION_MODE_STRICT), E_USER_DEPRECATED);
89-
90-
if ($constraint->strict) {
91-
$constraint->mode = Email::VALIDATION_MODE_STRICT;
92-
} else {
93-
$constraint->mode = Email::VALIDATION_MODE_LOOSE;
94-
}
95-
}
96-
9768
if (null === $constraint->mode) {
9869
$constraint->mode = $this->defaultMode;
9970
}
@@ -128,42 +99,5 @@ public function validate($value, Constraint $constraint)
12899

129100
return;
130101
}
131-
132-
$host = (string) substr($value, strrpos($value, '@') + 1);
133-
134-
// Check for host DNS resource records
135-
if ($constraint->checkMX) {
136-
if (!$this->checkMX($host)) {
137-
$this->context->buildViolation($constraint->message)
138-
->setParameter('{{ value }}', $this->formatValue($value))
139-
->setCode(Email::MX_CHECK_FAILED_ERROR)
140-
->addViolation();
141-
}
142-
143-
return;
144-
}
145-
146-
if ($constraint->checkHost && !$this->checkHost($host)) {
147-
$this->context->buildViolation($constraint->message)
148-
->setParameter('{{ value }}', $this->formatValue($value))
149-
->setCode(Email::HOST_CHECK_FAILED_ERROR)
150-
->addViolation();
151-
}
152-
}
153-
154-
/**
155-
* Check DNS Records for MX type.
156-
*/
157-
private function checkMX(string $host): bool
158-
{
159-
return '' !== $host && checkdnsrr($host, 'MX');
160-
}
161-
162-
/**
163-
* Check if one of MX, A or AAAA DNS RR exists.
164-
*/
165-
private function checkHost(string $host): bool
166-
{
167-
return '' !== $host && ($this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA')));
168102
}
169103
}

src/Symfony/Component/Validator/Constraints/Locale.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,10 @@ class Locale extends Constraint
3030
];
3131

3232
public $message = 'This value is not a valid locale.';
33-
public $canonicalize = false;
33+
public $canonicalize = true;
3434

3535
public function __construct($options = null)
3636
{
37-
if (!($options['canonicalize'] ?? false)) {
38-
@trigger_error('The "canonicalize" option with value "false" is deprecated since Symfony 4.1, set it to "true" instead.', E_USER_DEPRECATED);
39-
}
40-
4137
if (!class_exists(Locales::class)) {
4238
throw new LogicException('The Intl component is required to use the Locale constraint. Try running "composer require symfony/intl".');
4339
}

src/Symfony/Component/Validator/Context/ExecutionContext.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Validator\Context;
1313

14-
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
1514
use Symfony\Component\Validator\Constraint;
1615
use Symfony\Component\Validator\ConstraintViolation;
1716
use Symfony\Component\Validator\ConstraintViolationList;
@@ -128,24 +127,12 @@ class ExecutionContext implements ExecutionContextInterface
128127
private $initializedObjects;
129128

130129
/**
131-
* Creates a new execution context.
130+
* @param mixed $root The root value of the validated object graph
132131
*
133-
* @param ValidatorInterface $validator The validator
134-
* @param mixed $root The root value of the
135-
* validated object graph
136-
* @param TranslatorInterface $translator The translator
137-
* @param string|null $translationDomain The translation domain to
138-
* use for translating
139-
* violation messages
140-
*
141-
* @internal Called by {@link ExecutionContextFactory}. Should not be used
142-
* in user code.
132+
* @internal Called by {@link ExecutionContextFactory}. Should not be used in user code.
143133
*/
144-
public function __construct(ValidatorInterface $validator, $root, $translator, string $translationDomain = null)
134+
public function __construct(ValidatorInterface $validator, $root, TranslatorInterface $translator, string $translationDomain = null)
145135
{
146-
if (!$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
147-
throw new \TypeError(sprintf('Argument 3 passed to %s() must be an instance of %s, %s given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
148-
}
149136
$this->validator = $validator;
150137
$this->root = $root;
151138
$this->translator = $translator;

src/Symfony/Component/Validator/Context/ExecutionContextFactory.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Validator\Context;
1313

14-
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
1514
use Symfony\Component\Validator\Validator\ValidatorInterface;
1615
use Symfony\Contracts\Translation\TranslatorInterface;
1716

@@ -27,20 +26,8 @@ class ExecutionContextFactory implements ExecutionContextFactoryInterface
2726
private $translator;
2827
private $translationDomain;
2928

30-
/**
31-
* Creates a new context factory.
32-
*
33-
* @param TranslatorInterface $translator The translator
34-
* @param string|null $translationDomain The translation domain to
35-
* use for translating
36-
* violation messages
37-
*/
38-
public function __construct($translator, string $translationDomain = null)
29+
public function __construct(TranslatorInterface$translator, string $translationDomain = null)
3930
{
40-
if (!$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
41-
throw new \TypeError(sprintf('Argument 1 passed to %s() must be an instance of %s, %s given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
42-
}
43-
4431
$this->translator = $translator;
4532
$this->translationDomain = $translationDomain;
4633
}

src/Symfony/Component/Validator/DependencyInjection/AddValidatorInitializersPass.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Definition;
1818
use Symfony\Component\DependencyInjection\Reference;
19-
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
20-
use Symfony\Component\Validator\Util\LegacyTranslatorProxy;
2119

2220
/**
2321
* @author Fabien Potencier <fabien@symfony.com>
@@ -46,33 +44,5 @@ public function process(ContainerBuilder $container)
4644
}
4745

4846
$container->getDefinition($this->builderService)->addMethodCall('addObjectInitializers', [$initializers]);
49-
50-
// @deprecated logic, to be removed in Symfony 5.0
51-
$builder = $container->getDefinition($this->builderService);
52-
$calls = [];
53-
54-
foreach ($builder->getMethodCalls() as list($method, $arguments)) {
55-
if ('setTranslator' === $method) {
56-
if (!$arguments[0] instanceof Reference) {
57-
$translator = $arguments[0];
58-
} elseif ($container->has($arguments[0])) {
59-
$translator = $container->findDefinition($arguments[0]);
60-
} else {
61-
continue;
62-
}
63-
64-
while (!($class = $translator->getClass()) && $translator instanceof ChildDefinition) {
65-
$translator = $container->findDefinition($translator->getParent());
66-
}
67-
68-
if (!is_subclass_of($class, LegacyTranslatorInterface::class)) {
69-
$arguments[0] = (new Definition(LegacyTranslatorProxy::class))->addArgument($arguments[0]);
70-
}
71-
}
72-
73-
$calls[] = [$method, $arguments];
74-
}
75-
76-
$builder->setMethodCalls($calls);
7747
}
7848
}

src/Symfony/Component/Validator/Tests/Constraints/EmailTest.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@
1616

1717
class EmailTest extends TestCase
1818
{
19-
/**
20-
* @expectedDeprecation The "strict" property is deprecated since Symfony 4.1. Use "mode"=>"strict" instead.
21-
* @group legacy
22-
*/
23-
public function testLegacyConstructorStrict()
24-
{
25-
$subject = new Email(['strict' => true]);
26-
27-
$this->assertTrue($subject->strict);
28-
}
29-
3019
public function testConstructorStrict()
3120
{
3221
$subject = new Email(['mode' => Email::VALIDATION_MODE_STRICT]);

0 commit comments

Comments
 (0)
0