8000 [Validator] deprecate checkMX and checkHost on Email validator · symfony/symfony@d16af55 · GitHub
[go: up one dir, main page]

Skip to content

Commit d16af55

Browse files
committed
[Validator] deprecate checkMX and checkHost on Email validator
1 parent f0bcab5 commit d16af55

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

UPGRADE-4.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ TwigBundle
261261
Validator
262262
---------
263263

264+
* The strict, checkMX, and checkHost properties of the Email validator are deprecated
264265
* The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead
265266
* The `ValidatorBuilderInterface` has been deprecated and `ValidatorBuilder` made final
266267
* 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.

UPGRADE-5.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ TwigBundle
238238
Validator
239239
--------
240240

241+
* The strict, checkMX, and checkHost properties of the Email validator were removed
241242
* The `Email::__construct()` 'strict' property has been removed. Use 'mode'=>"strict" instead.
242243
* Calling `EmailValidator::__construct()` method with a boolean parameter has been removed, use `EmailValidator("strict")` instead.
243244
* Removed the `checkDNS` and `dnsMessage` options from the `Url` constraint.

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,19 @@ class Email extends Constraint
4949
);
5050

5151
public $message = 'This value is not a valid email address.';
52+
53+
/**
54+
* @deprecated since Symfony 4.2.
55+
*/
5256
public $checkMX = false;
57+
58+
/**
59+
* @deprecated since Symfony 4.2.
60+
*/
5361
public $checkHost = false;
5462

5563
/**
56-
* @deprecated since Symfony 4.1. Set mode to "strict" instead.
64+
* @deprecated since Symfony 4.1, set mode to "strict" instead.
5765
*/
5866
public $strict;
5967
public $mode;
@@ -64,6 +72,14 @@ public function __construct($options = null)
6472
@trigger_error(sprintf('The "strict" property is deprecated since Symfony 4.1. Use "mode"=>"%s" instead.', self::VALIDATION_MODE_STRICT), E_USER_DEPRECATED);
6573
}
6674

75+
if (\is_array($options) && array_key_exists('checkMX', $options)) {
76+
@trigger_error('The "checkMX" property is deprecated since Symfony 4.2.', E_USER_DEPRECATED);
77+
}
78+
79+
if (\is_array($options) && array_key_exists('checkHost', $options)) {
80+
@trigger_error('The "checkHost" property is deprecated since Symfony 4.2.', E_USER_DEPRECATED);
81+
}
82+
6783
if (\is_array($options) && array_key_exists('mode', $options) && !\in_array($options['mode'], self::$validationModes, true)) {
6884
throw new \InvalidArgumentException('The "mode" parameter value is not valid.');
6985
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public function validate($value, Constraint $constraint)
133133

134134
// Check for host DNS resource records
135135
if ($constraint->checkMX) {
136+
@trigger_error(sprintf('The %s::$checkMX property is deprecated since Symfony 4.2.', Email::class), E_USER_DEPRECATED);
137+
136138
if (!$this-> EDBE ;checkMX($host)) {
137139
$this->context->buildViolation($constraint->message)
138140
->setParameter('{{ value }}', $this->formatValue($value))
@@ -144,6 +146,8 @@ public function validate($value, Constraint $constraint)
144146
}
145147

146148
if ($constraint->checkHost && !$this->checkHost($host)) {
149+
@trigger_error(sprintf('The %s::$checkHost property is deprecated since Symfony 4.2.', Email::class), E_USER_DEPRECATED);
150+
147151
$this->context->buildViolation($constraint->message)
148152
->setParameter('{{ value }}', $this->formatValue($value))
149153
->setCode(Email::HOST_CHECK_FAILED_ERROR)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ public function getInvalidEmailsForStrictChecks()
317317
/**
318318
* @dataProvider getDnsChecks
319319
* @requires function Symfony\Bridge\PhpUnit\DnsMock::withMockedHosts
320+
* @group legacy
320321
*/
321322
public function testDnsChecks($type, $violation)
322323
{
@@ -353,6 +354,7 @@ public function getDnsChecks()
353354

354355
/**
355356
* @requires function Symfony\Bridge\PhpUnit\DnsMock::withMockedHosts
357+
* @group legacy
356358
*/
357359
public function testHostnameIsProperlyParsed()
358360
{
@@ -368,6 +370,7 @@ public function testHostnameIsProperlyParsed()
368370

369371
/**
370372
* @dataProvider provideCheckTypes
373+
* @group legacy
371374
*/
372375
public function testEmptyHostIsNotValid($checkType, $violation)
373376
{

0 commit comments

Comments
 (0)
0