From 3cfc4e9a4b5a25b704f110783969e9fdf21e347f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20L=C3=A9v=C3=AAque?= Date: Fri, 28 Jul 2023 17:28:09 +0200 Subject: [PATCH] Add option to required MX record on DNSCheckValidation --- src/Validation/DNSCheckValidation.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Validation/DNSCheckValidation.php b/src/Validation/DNSCheckValidation.php index 214d4f4c..da2ae2ca 100644 --- a/src/Validation/DNSCheckValidation.php +++ b/src/Validation/DNSCheckValidation.php @@ -63,7 +63,12 @@ class DNSCheckValidation implements EmailValidation */ private $dnsGetRecord; - public function __construct(?DNSGetRecordWrapper $dnsGetRecord = null) + /** + * @var bool + */ + private $requireMX; + + public function __construct(?DNSGetRecordWrapper $dnsGetRecord = null, bool $requireMX = false) { if (!function_exists('idn_to_ascii')) { throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__)); @@ -74,6 +79,7 @@ public function __construct(?DNSGetRecordWrapper $dnsGetRecord = null) } $this->dnsGetRecord = $dnsGetRecord; + $this->requireMX = $requireMX; } public function isValid(string $email, EmailLexer $emailLexer): bool @@ -174,6 +180,11 @@ private function validateDnsRecords($host): bool return false; } } + + if (empty($this->mxRecords) && $this->requireMX) { + $this->error = new InvalidEmail(new ReasonNoDNSRecord(), ''); + } + return true; }