@@ -4,6 +4,6 @@ |
||
4 | 4 | |
5 | 5 | class DomainHyphened extends InvalidEmail |
6 | 6 | { |
7 | - const CODE = 144; |
|
8 | - const REASON = "Hyphen found in domain"; |
|
7 | + const CODE = 144; |
|
8 | + const REASON = "Hyphen found in domain"; |
|
9 | 9 | } |
@@ -4,6 +4,6 @@ |
||
4 | 4 | |
5 | 5 | class ExpectingCTEXT extends InvalidEmail |
6 | 6 | { |
7 | - const CODE = 139; |
|
8 | - const REASON = "Expecting CTEXT"; |
|
7 | + const CODE = 139; |
|
8 | + const REASON = "Expecting CTEXT"; |
|
9 | 9 | } |
@@ -4,6 +4,6 @@ |
||
4 | 4 | |
5 | 5 | class CharNotAllowed extends InvalidEmail |
6 | 6 | { |
7 | - const CODE = 201; |
|
8 | - const REASON = "Non allowed character in domain"; |
|
7 | + const CODE = 201; |
|
8 | + const REASON = "Non allowed character in domain"; |
|
9 | 9 | } |
@@ -7,118 +7,118 @@ |
||
7 | 7 | |
8 | 8 | class MultipleValidationWithAnd implements EmailValidation |
9 | 9 | { |
10 | - /** |
|
11 | - * If one of validations gets failure skips all succeeding validation. |
|
12 | - * This means MultipleErrors will only contain a single error which first found. |
|
13 | - */ |
|
14 | - const STOP_ON_ERROR = 0; |
|
15 | - |
|
16 | - /** |
|
17 | - * All of validations will be invoked even if one of them got failure. |
|
18 | - * So MultipleErrors will contain all causes. |
|
19 | - */ |
|
20 | - const ALLOW_ALL_ERRORS = 1; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var EmailValidation[] |
|
24 | - */ |
|
25 | - private $validations = []; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - private $warnings = []; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var MultipleErrors|null |
|
34 | - */ |
|
35 | - private $error; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var int |
|
39 | - */ |
|
40 | - private $mode; |
|
41 | - |
|
42 | - /** |
|
43 | - * @param EmailValidation[] $validations The validations. |
|
44 | - * @param int $mode The validation mode (one of the constants). |
|
45 | - */ |
|
46 | - public function __construct(array $validations, $mode = self::ALLOW_ALL_ERRORS) |
|
47 | - { |
|
48 | - if (count($validations) == 0) { |
|
49 | - throw new EmptyValidationList(); |
|
50 | - } |
|
51 | - |
|
52 | - $this->validations = $validations; |
|
53 | - $this->mode = $mode; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * {@inheritdoc} |
|
58 | - */ |
|
59 | - public function isValid($email, EmailLexer $emailLexer) |
|
60 | - { |
|
61 | - $result = true; |
|
62 | - $errors = []; |
|
63 | - foreach ($this->validations as $validation) { |
|
64 | - $emailLexer->reset(); |
|
65 | - $validationResult = $validation->isValid($email, $emailLexer); |
|
66 | - $result = $result && $validationResult; |
|
67 | - $this->warnings = array_merge($this->warnings, $validation->getWarnings()); |
|
68 | - $errors = $this->addNewError($validation->getError(), $errors); |
|
69 | - |
|
70 | - if ($this->shouldStop($result)) { |
|
71 | - break; |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - if (!empty($errors)) { |
|
76 | - $this->error = new MultipleErrors($errors); |
|
77 | - } |
|
78 | - |
|
79 | - return $result; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @param \Egulias\EmailValidator\Exception\InvalidEmail|null $possibleError |
|
84 | - * @param \Egulias\EmailValidator\Exception\InvalidEmail[] $errors |
|
85 | - * |
|
86 | - * @return \Egulias\EmailValidator\Exception\InvalidEmail[] |
|
87 | - */ |
|
88 | - private function addNewError($possibleError, array $errors) |
|
89 | - { |
|
90 | - if (null !== $possibleError) { |
|
91 | - $errors[] = $possibleError; |
|
92 | - } |
|
93 | - |
|
94 | - return $errors; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @param bool $result |
|
99 | - * |
|
100 | - * @return bool |
|
101 | - */ |
|
102 | - private function shouldStop($result) |
|
103 | - { |
|
104 | - return !$result && $this->mode === self::STOP_ON_ERROR; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Returns the validation errors. |
|
109 | - * |
|
110 | - * @return MultipleErrors|null |
|
111 | - */ |
|
112 | - public function getError() |
|
113 | - { |
|
114 | - return $this->error; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * {@inheritdoc} |
|
119 | - */ |
|
120 | - public function getWarnings() |
|
121 | - { |
|
122 | - return $this->warnings; |
|
123 | - } |
|
10 | + /** |
|
11 | + * If one of validations gets failure skips all succeeding validation. |
|
12 | + * This means MultipleErrors will only contain a single error which first found. |
|
13 | + */ |
|
14 | + const STOP_ON_ERROR = 0; |
|
15 | + |
|
16 | + /** |
|
17 | + * All of validations will be invoked even if one of them got failure. |
|
18 | + * So MultipleErrors will contain all causes. |
|
19 | + */ |
|
20 | + const ALLOW_ALL_ERRORS = 1; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var EmailValidation[] |
|
24 | + */ |
|
25 | + private $validations = []; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + private $warnings = []; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var MultipleErrors|null |
|
34 | + */ |
|
35 | + private $error; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var int |
|
39 | + */ |
|
40 | + private $mode; |
|
41 | + |
|
42 | + /** |
|
43 | + * @param EmailValidation[] $validations The validations. |
|
44 | + * @param int $mode The validation mode (one of the constants). |
|
45 | + */ |
|
46 | + public function __construct(array $validations, $mode = self::ALLOW_ALL_ERRORS) |
|
47 | + { |
|
48 | + if (count($validations) == 0) { |
|
49 | + throw new EmptyValidationList(); |
|
50 | + } |
|
51 | + |
|
52 | + $this->validations = $validations; |
|
53 | + $this->mode = $mode; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * {@inheritdoc} |
|
58 | + */ |
|
59 | + public function isValid($email, EmailLexer $emailLexer) |
|
60 | + { |
|
61 | + $result = true; |
|
62 | + $errors = []; |
|
63 | + foreach ($this->validations as $validation) { |
|
64 | + $emailLexer->reset(); |
|
65 | + $validationResult = $validation->isValid($email, $emailLexer); |
|
66 | + $result = $result && $validationResult; |
|
67 | + $this->warnings = array_merge($this->warnings, $validation->getWarnings()); |
|
68 | + $errors = $this->addNewError($validation->getError(), $errors); |
|
69 | + |
|
70 | + if ($this->shouldStop($result)) { |
|
71 | + break; |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + if (!empty($errors)) { |
|
76 | + $this->error = new MultipleErrors($errors); |
|
77 | + } |
|
78 | + |
|
79 | + return $result; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @param \Egulias\EmailValidator\Exception\InvalidEmail|null $possibleError |
|
84 | + * @param \Egulias\EmailValidator\Exception\InvalidEmail[] $errors |
|
85 | + * |
|
86 | + * @return \Egulias\EmailValidator\Exception\InvalidEmail[] |
|
87 | + */ |
|
88 | + private function addNewError($possibleError, array $errors) |
|
89 | + { |
|
90 | + if (null !== $possibleError) { |
|
91 | + $errors[] = $possibleError; |
|
92 | + } |
|
93 | + |
|
94 | + return $errors; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @param bool $result |
|
99 | + * |
|
100 | + * @return bool |
|
101 | + */ |
|
102 | + private function shouldStop($result) |
|
103 | + { |
|
104 | + return !$result && $this->mode === self::STOP_ON_ERROR; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Returns the validation errors. |
|
109 | + * |
|
110 | + * @return MultipleErrors|null |
|
111 | + */ |
|
112 | + public function getError() |
|
113 | + { |
|
114 | + return $this->error; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * {@inheritdoc} |
|
119 | + */ |
|
120 | + public function getWarnings() |
|
121 | + { |
|
122 | + return $this->warnings; |
|
123 | + } |
|
124 | 124 | } |
@@ -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 | } |
@@ -99,7 +99,7 @@ |
||
99 | 99 | { |
100 | 100 | $variant = INTL_IDNA_VARIANT_UTS46; |
101 | 101 | |
102 | - $host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.') . '.'; |
|
102 | + $host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.').'.'; |
|
103 | 103 | |
104 | 104 | return $this->validateDnsRecords($host); |
105 | 105 | } |
@@ -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 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | { |
28 | 28 | $this->parser = new EmailParser($emailLexer); |
29 | 29 | try { |
30 | - $this->parser->parse((string)$email); |
|
30 | + $this->parser->parse((string) $email); |
|
31 | 31 | } catch (InvalidEmail $invalid) { |
32 | 32 | $this->error = $invalid; |
33 | 33 | return false; |
@@ -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 | } |