@@ -6,6 +6,6 @@ |
||
| 6 | 6 | |
| 7 | 7 | class SpoofEmail extends InvalidEmail |
| 8 | 8 | { |
| 9 | - const CODE = 998; |
|
| 10 | - const REASON = "The email contains mixed UTF8 chars that makes it suspicious"; |
|
| 9 | + const CODE = 998; |
|
| 10 | + const REASON = "The email contains mixed UTF8 chars that makes it suspicious"; |
|
| 11 | 11 | } |
@@ -6,6 +6,6 @@ |
||
| 6 | 6 | |
| 7 | 7 | class RFCWarnings extends InvalidEmail |
| 8 | 8 | { |
| 9 | - const CODE = 997; |
|
| 10 | - const REASON = 'Warnings were found.'; |
|
| 9 | + const CODE = 997; |
|
| 10 | + const REASON = 'Warnings were found.'; |
|
| 11 | 11 | } |
@@ -11,156 +11,156 @@ |
||
| 11 | 11 | |
| 12 | 12 | class DNSCheckValidation implements EmailValidation |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var array |
|
| 16 | - */ |
|
| 17 | - private $warnings = []; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @var InvalidEmail|null |
|
| 21 | - */ |
|
| 22 | - private $error; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 27 | - private $mxRecords = []; |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - public function __construct() |
|
| 31 | - { |
|
| 32 | - if (!function_exists('idn_to_ascii')) { |
|
| 33 | - throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__)); |
|
| 34 | - } |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function isValid($email, EmailLexer $emailLexer) |
|
| 38 | - { |
|
| 39 | - // use the input to check DNS if we cannot extract something similar to a domain |
|
| 40 | - $host = $email; |
|
| 41 | - |
|
| 42 | - // Arguable pattern to extract the domain. Not aiming to validate the domain nor the email |
|
| 43 | - if (false !== $lastAtPos = strrpos($email, '@')) { |
|
| 44 | - $host = substr($email, $lastAtPos + 1); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - // Get the domain parts |
|
| 48 | - $hostParts = explode('.', $host); |
|
| 49 | - |
|
| 50 | - // Reserved Top Level DNS Names (https://tools.ietf.org/html/rfc2606#section-2), |
|
| 51 | - // mDNS and private DNS Namespaces (https://tools.ietf.org/html/rfc6762#appendix-G) |
|
| 52 | - $reservedTopLevelDnsNames = [ |
|
| 53 | - // Reserved Top Level DNS Names |
|
| 54 | - 'test', |
|
| 55 | - 'example', |
|
| 56 | - 'invalid', |
|
| 57 | - 'localhost', |
|
| 58 | - |
|
| 59 | - // mDNS |
|
| 60 | - 'local', |
|
| 61 | - |
|
| 62 | - // Private DNS Namespaces |
|
| 63 | - 'intranet', |
|
| 64 | - 'internal', |
|
| 65 | - 'private', |
|
| 66 | - 'corp', |
|
| 67 | - 'home', |
|
| 68 | - 'lan', |
|
| 69 | - ]; |
|
| 70 | - |
|
| 71 | - $isLocalDomain = count($hostParts) <= 1; |
|
| 72 | - $isReservedTopLevel = in_array($hostParts[(count($hostParts) - 1)], $reservedTopLevelDnsNames, true); |
|
| 73 | - |
|
| 74 | - // Exclude reserved top level DNS names |
|
| 75 | - if ($isLocalDomain || $isReservedTopLevel) { |
|
| 76 | - $this->error = new LocalOrReservedDomain(); |
|
| 77 | - return false; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - return $this->checkDns($host); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - public function getError() |
|
| 84 | - { |
|
| 85 | - return $this->error; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - public function getWarnings() |
|
| 89 | - { |
|
| 90 | - return $this->warnings; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @param string $host |
|
| 95 | - * |
|
| 96 | - * @return bool |
|
| 97 | - */ |
|
| 98 | - protected function checkDns($host) |
|
| 99 | - { |
|
| 100 | - $variant = INTL_IDNA_VARIANT_UTS46; |
|
| 101 | - |
|
| 102 | - $host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.') . '.'; |
|
| 103 | - |
|
| 104 | - return $this->validateDnsRecords($host); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Validate the DNS records for given host. |
|
| 110 | - * |
|
| 111 | - * @param string $host A set of DNS records in the format returned by dns_get_record. |
|
| 112 | - * |
|
| 113 | - * @return bool True on success. |
|
| 114 | - */ |
|
| 115 | - private function validateDnsRecords($host) |
|
| 116 | - { |
|
| 117 | - // Get all MX, A and AAAA DNS records for host |
|
| 118 | - // Using @ as workaround to fix https://bugs.php.net/bug.php?id=73149 |
|
| 119 | - $dnsRecords = @dns_get_record($host, DNS_MX + DNS_A + DNS_AAAA); |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - // No MX, A or AAAA DNS records |
|
| 123 | - if (empty($dnsRecords)) { |
|
| 124 | - $this->error = new NoDNSRecord(); |
|
| 125 | - return false; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - // For each DNS record |
|
| 129 | - foreach ($dnsRecords as $dnsRecord) { |
|
| 130 | - if (!$this->validateMXRecord($dnsRecord)) { |
|
| 131 | - return false; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // No MX records (fallback to A or AAAA records) |
|
| 136 | - if (empty($this->mxRecords)) { |
|
| 137 | - $this->warnings[NoDNSMXRecord::CODE] = new NoDNSMXRecord(); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - return true; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Validate an MX record |
|
| 145 | - * |
|
| 146 | - * @param array $dnsRecord Given DNS record. |
|
| 147 | - * |
|
| 148 | - * @return bool True if valid. |
|
| 149 | - */ |
|
| 150 | - private function validateMxRecord($dnsRecord) |
|
| 151 | - { |
|
| 152 | - if ($dnsRecord['type'] !== 'MX') { |
|
| 153 | - return true; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - // "Null MX" record indicates the domain accepts no mail (https://tools.ietf.org/html/rfc7505) |
|
| 157 | - if (empty($dnsRecord['target']) || $dnsRecord['target'] === '.') { |
|
| 158 | - $this->error = new DomainAcceptsNoMail(); |
|
| 159 | - return false; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - $this->mxRecords[] = $dnsRecord; |
|
| 163 | - |
|
| 164 | - return true; |
|
| 165 | - } |
|
| 14 | + /** |
|
| 15 | + * @var array |
|
| 16 | + */ |
|
| 17 | + private $warnings = []; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @var InvalidEmail|null |
|
| 21 | + */ |
|
| 22 | + private $error; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | + private $mxRecords = []; |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + public function __construct() |
|
| 31 | + { |
|
| 32 | + if (!function_exists('idn_to_ascii')) { |
|
| 33 | + throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__)); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function isValid($email, EmailLexer $emailLexer) |
|
| 38 | + { |
|
| 39 | + // use the input to check DNS if we cannot extract something similar to a domain |
|
| 40 | + $host = $email; |
|
| 41 | + |
|
| 42 | + // Arguable pattern to extract the domain. Not aiming to validate the domain nor the email |
|
| 43 | + if (false !== $lastAtPos = strrpos($email, '@')) { |
|
| 44 | + $host = substr($email, $lastAtPos + 1); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + // Get the domain parts |
|
| 48 | + $hostParts = explode('.', $host); |
|
| 49 | + |
|
| 50 | + // Reserved Top Level DNS Names (https://tools.ietf.org/html/rfc2606#section-2), |
|
| 51 | + // mDNS and private DNS Namespaces (https://tools.ietf.org/html/rfc6762#appendix-G) |
|
| 52 | + $reservedTopLevelDnsNames = [ |
|
| 53 | + // Reserved Top Level DNS Names |
|
| 54 | + 'test', |
|
| 55 | + 'example', |
|
| 56 | + 'invalid', |
|
| 57 | + 'localhost', |
|
| 58 | + |
|
| 59 | + // mDNS |
|
| 60 | + 'local', |
|
| 61 | + |
|
| 62 | + // Private DNS Namespaces |
|
| 63 | + 'intranet', |
|
| 64 | + 'internal', |
|
| 65 | + 'private', |
|
| 66 | + 'corp', |
|
| 67 | + 'home', |
|
| 68 | + 'lan', |
|
| 69 | + ]; |
|
| 70 | + |
|
| 71 | + $isLocalDomain = count($hostParts) <= 1; |
|
| 72 | + $isReservedTopLevel = in_array($hostParts[(count($hostParts) - 1)], $reservedTopLevelDnsNames, true); |
|
| 73 | + |
|
| 74 | + // Exclude reserved top level DNS names |
|
| 75 | + if ($isLocalDomain || $isReservedTopLevel) { |
|
| 76 | + $this->error = new LocalOrReservedDomain(); |
|
| 77 | + return false; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + return $this->checkDns($host); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + public function getError() |
|
| 84 | + { |
|
| 85 | + return $this->error; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + public function getWarnings() |
|
| 89 | + { |
|
| 90 | + return $this->warnings; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @param string $host |
|
| 95 | + * |
|
| 96 | + * @return bool |
|
| 97 | + */ |
|
| 98 | + protected function checkDns($host) |
|
| 99 | + { |
|
| 100 | + $variant = INTL_IDNA_VARIANT_UTS46; |
|
| 101 | + |
|
| 102 | + $host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.') . '.'; |
|
| 103 | + |
|
| 104 | + return $this->validateDnsRecords($host); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Validate the DNS records for given host. |
|
| 110 | + * |
|
| 111 | + * @param string $host A set of DNS records in the format returned by dns_get_record. |
|
| 112 | + * |
|
| 113 | + * @return bool True on success. |
|
| 114 | + */ |
|
| 115 | + private function validateDnsRecords($host) |
|
| 116 | + { |
|
| 117 | + // Get all MX, A and AAAA DNS records for host |
|
| 118 | + // Using @ as workaround to fix https://bugs.php.net/bug.php?id=73149 |
|
| 119 | + $dnsRecords = @dns_get_record($host, DNS_MX + DNS_A + DNS_AAAA); |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + // No MX, A or AAAA DNS records |
|
| 123 | + if (empty($dnsRecords)) { |
|
| 124 | + $this->error = new NoDNSRecord(); |
|
| 125 | + return false; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + // For each DNS record |
|
| 129 | + foreach ($dnsRecords as $dnsRecord) { |
|
| 130 | + if (!$this->validateMXRecord($dnsRecord)) { |
|
| 131 | + return false; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // No MX records (fallback to A or AAAA records) |
|
| 136 | + if (empty($this->mxRecords)) { |
|
| 137 | + $this->warnings[NoDNSMXRecord::CODE] = new NoDNSMXRecord(); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + return true; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Validate an MX record |
|
| 145 | + * |
|
| 146 | + * @param array $dnsRecord Given DNS record. |
|
| 147 | + * |
|
| 148 | + * @return bool True if valid. |
|
| 149 | + */ |
|
| 150 | + private function validateMxRecord($dnsRecord) |
|
| 151 | + { |
|
| 152 | + if ($dnsRecord['type'] !== 'MX') { |
|
| 153 | + return true; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + // "Null MX" record indicates the domain accepts no mail (https://tools.ietf.org/html/rfc7505) |
|
| 157 | + if (empty($dnsRecord['target']) || $dnsRecord['target'] === '.') { |
|
| 158 | + $this->error = new DomainAcceptsNoMail(); |
|
| 159 | + return false; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + $this->mxRecords[] = $dnsRecord; |
|
| 163 | + |
|
| 164 | + return true; |
|
| 165 | + } |
|
| 166 | 166 | } |
@@ -8,42 +8,42 @@ |
||
| 8 | 8 | |
| 9 | 9 | class RFCValidation implements EmailValidation |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @var EmailParser|null |
|
| 13 | - */ |
|
| 14 | - private $parser; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - private $warnings = []; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var InvalidEmail|null |
|
| 23 | - */ |
|
| 24 | - private $error; |
|
| 25 | - |
|
| 26 | - public function isValid($email, EmailLexer $emailLexer) |
|
| 27 | - { |
|
| 28 | - $this->parser = new EmailParser($emailLexer); |
|
| 29 | - try { |
|
| 30 | - $this->parser->parse((string)$email); |
|
| 31 | - } catch (InvalidEmail $invalid) { |
|
| 32 | - $this->error = $invalid; |
|
| 33 | - return false; |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - $this->warnings = $this->parser->getWarnings(); |
|
| 37 | - return true; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - public function getError() |
|
| 41 | - { |
|
| 42 | - return $this->error; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function getWarnings() |
|
| 46 | - { |
|
| 47 | - return $this->warnings; |
|
| 48 | - } |
|
| 11 | + /** |
|
| 12 | + * @var EmailParser|null |
|
| 13 | + */ |
|
| 14 | + private $parser; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + private $warnings = []; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var InvalidEmail|null |
|
| 23 | + */ |
|
| 24 | + private $error; |
|
| 25 | + |
|
| 26 | + public function isValid($email, EmailLexer $emailLexer) |
|
| 27 | + { |
|
| 28 | + $this->parser = new EmailParser($emailLexer); |
|
| 29 | + try { |
|
| 30 | + $this->parser->parse((string)$email); |
|
| 31 | + } catch (InvalidEmail $invalid) { |
|
| 32 | + $this->error = $invalid; |
|
| 33 | + return false; |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + $this->warnings = $this->parser->getWarnings(); |
|
| 37 | + return true; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + public function getError() |
|
| 41 | + { |
|
| 42 | + return $this->error; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function getWarnings() |
|
| 46 | + { |
|
| 47 | + return $this->warnings; |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -8,27 +8,27 @@ |
||
| 8 | 8 | |
| 9 | 9 | interface EmailValidation |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * Returns true if the given email is valid. |
|
| 13 | - * |
|
| 14 | - * @param string $email The email you want to validate. |
|
| 15 | - * @param EmailLexer $emailLexer The email lexer. |
|
| 16 | - * |
|
| 17 | - * @return bool |
|
| 18 | - */ |
|
| 19 | - public function isValid($email, EmailLexer $emailLexer); |
|
| 11 | + /** |
|
| 12 | + * Returns true if the given email is valid. |
|
| 13 | + * |
|
| 14 | + * @param string $email The email you want to validate. |
|
| 15 | + * @param EmailLexer $emailLexer The email lexer. |
|
| 16 | + * |
|
| 17 | + * @return bool |
|
| 18 | + */ |
|
| 19 | + public function isValid($email, EmailLexer $emailLexer); |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Returns the validation error. |
|
| 23 | - * |
|
| 24 | - * @return InvalidEmail|null |
|
| 25 | - */ |
|
| 26 | - public function getError(); |
|
| 21 | + /** |
|
| 22 | + * Returns the validation error. |
|
| 23 | + * |
|
| 24 | + * @return InvalidEmail|null |
|
| 25 | + */ |
|
| 26 | + public function getError(); |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Returns the validation warnings. |
|
| 30 | - * |
|
| 31 | - * @return Warning[] |
|
| 32 | - */ |
|
| 33 | - public function getWarnings(); |
|
| 28 | + /** |
|
| 29 | + * Returns the validation warnings. |
|
| 30 | + * |
|
| 31 | + * @return Warning[] |
|
| 32 | + */ |
|
| 33 | + public function getWarnings(); |
|
| 34 | 34 | } |
@@ -6,11 +6,11 @@ |
||
| 6 | 6 | |
| 7 | 7 | class EmptyValidationList extends \InvalidArgumentException |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @param int $code |
|
| 11 | - */ |
|
| 12 | - public function __construct($code = 0, Exception $previous = null) |
|
| 13 | - { |
|
| 14 | - parent::__construct("Empty validation list is not allowed", $code, $previous); |
|
| 15 | - } |
|
| 9 | + /** |
|
| 10 | + * @param int $code |
|
| 11 | + */ |
|
| 12 | + public function __construct($code = 0, Exception $previous = null) |
|
| 13 | + { |
|
| 14 | + parent::__construct("Empty validation list is not allowed", $code, $previous); |
|
| 15 | + } |
|
| 16 | 16 | } |
@@ -9,43 +9,43 @@ |
||
| 9 | 9 | |
| 10 | 10 | class SpoofCheckValidation implements EmailValidation |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @var InvalidEmail|null |
|
| 14 | - */ |
|
| 15 | - private $error; |
|
| 16 | - |
|
| 17 | - public function __construct() |
|
| 18 | - { |
|
| 19 | - if (!extension_loaded('intl')) { |
|
| 20 | - throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__)); |
|
| 21 | - } |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @psalm-suppress InvalidArgument |
|
| 26 | - */ |
|
| 27 | - public function isValid($email, EmailLexer $emailLexer) |
|
| 28 | - { |
|
| 29 | - $checker = new Spoofchecker(); |
|
| 30 | - $checker->setChecks(Spoofchecker::SINGLE_SCRIPT); |
|
| 31 | - |
|
| 32 | - if ($checker->isSuspicious($email)) { |
|
| 33 | - $this->error = new SpoofEmail(); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - return $this->error === null; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @return InvalidEmail|null |
|
| 41 | - */ |
|
| 42 | - public function getError() |
|
| 43 | - { |
|
| 44 | - return $this->error; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function getWarnings() |
|
| 48 | - { |
|
| 49 | - return []; |
|
| 50 | - } |
|
| 12 | + /** |
|
| 13 | + * @var InvalidEmail|null |
|
| 14 | + */ |
|
| 15 | + private $error; |
|
| 16 | + |
|
| 17 | + public function __construct() |
|
| 18 | + { |
|
| 19 | + if (!extension_loaded('intl')) { |
|
| 20 | + throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__)); |
|
| 21 | + } |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @psalm-suppress InvalidArgument |
|
| 26 | + */ |
|
| 27 | + public function isValid($email, EmailLexer $emailLexer) |
|
| 28 | + { |
|
| 29 | + $checker = new Spoofchecker(); |
|
| 30 | + $checker->setChecks(Spoofchecker::SINGLE_SCRIPT); |
|
| 31 | + |
|
| 32 | + if ($checker->isSuspicious($email)) { |
|
| 33 | + $this->error = new SpoofEmail(); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + return $this->error === null; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @return InvalidEmail|null |
|
| 41 | + */ |
|
| 42 | + public function getError() |
|
| 43 | + { |
|
| 44 | + return $this->error; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function getWarnings() |
|
| 48 | + { |
|
| 49 | + return []; |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -8,34 +8,34 @@ |
||
| 8 | 8 | |
| 9 | 9 | class NoRFCWarningsValidation extends RFCValidation |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @var InvalidEmail|null |
|
| 13 | - */ |
|
| 14 | - private $error; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * {@inheritdoc} |
|
| 18 | - */ |
|
| 19 | - public function isValid($email, EmailLexer $emailLexer) |
|
| 20 | - { |
|
| 21 | - if (!parent::isValid($email, $emailLexer)) { |
|
| 22 | - return false; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - if (empty($this->getWarnings())) { |
|
| 26 | - return true; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - $this->error = new RFCWarnings(); |
|
| 30 | - |
|
| 31 | - return false; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * {@inheritdoc} |
|
| 36 | - */ |
|
| 37 | - public function getError() |
|
| 38 | - { |
|
| 39 | - return $this->error ?: parent::getError(); |
|
| 40 | - } |
|
| 11 | + /** |
|
| 12 | + * @var InvalidEmail|null |
|
| 13 | + */ |
|
| 14 | + private $error; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * {@inheritdoc} |
|
| 18 | + */ |
|
| 19 | + public function isValid($email, EmailLexer $emailLexer) |
|
| 20 | + { |
|
| 21 | + if (!parent::isValid($email, $emailLexer)) { |
|
| 22 | + return false; |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + if (empty($this->getWarnings())) { |
|
| 26 | + return true; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + $this->error = new RFCWarnings(); |
|
| 30 | + |
|
| 31 | + return false; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * {@inheritdoc} |
|
| 36 | + */ |
|
| 37 | + public function getError() |
|
| 38 | + { |
|
| 39 | + return $this->error ?: parent::getError(); |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -6,27 +6,27 @@ |
||
| 6 | 6 | |
| 7 | 7 | class MultipleErrors extends InvalidEmail |
| 8 | 8 | { |
| 9 | - const CODE = 999; |
|
| 10 | - const REASON = "Accumulated errors for multiple validations"; |
|
| 11 | - /** |
|
| 12 | - * @var InvalidEmail[] |
|
| 13 | - */ |
|
| 14 | - private $errors = []; |
|
| 9 | + const CODE = 999; |
|
| 10 | + const REASON = "Accumulated errors for multiple validations"; |
|
| 11 | + /** |
|
| 12 | + * @var InvalidEmail[] |
|
| 13 | + */ |
|
| 14 | + private $errors = []; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @param InvalidEmail[] $errors |
|
| 18 | - */ |
|
| 19 | - public function __construct(array $errors) |
|
| 20 | - { |
|
| 21 | - $this->errors = $errors; |
|
| 22 | - parent::__construct(); |
|
| 23 | - } |
|
| 16 | + /** |
|
| 17 | + * @param InvalidEmail[] $errors |
|
| 18 | + */ |
|
| 19 | + public function __construct(array $errors) |
|
| 20 | + { |
|
| 21 | + $this->errors = $errors; |
|
| 22 | + parent::__construct(); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @return InvalidEmail[] |
|
| 27 | - */ |
|
| 28 | - public function getErrors() |
|
| 29 | - { |
|
| 30 | - return $this->errors; |
|
| 31 | - } |
|
| 25 | + /** |
|
| 26 | + * @return InvalidEmail[] |
|
| 27 | + */ |
|
| 28 | + public function getErrors() |
|
| 29 | + { |
|
| 30 | + return $this->errors; |
|
| 31 | + } |
|
| 32 | 32 | } |