1 | <?php |
||
25 | class EmailValidator implements ValidatorInterface |
||
26 | { |
||
27 | |||
28 | use \Maslosoft\Mangan\Validators\Traits\AllowEmpty, |
||
29 | \Maslosoft\Mangan\Validators\Traits\Messages, |
||
30 | \Maslosoft\Mangan\Validators\Traits\OnScenario, |
||
31 | \Maslosoft\Mangan\Validators\Traits\Safe; |
||
32 | |||
33 | /** |
||
34 | * @var string the regular expression used to validate the attribute value. |
||
35 | * @see http://www.regular-expressions.info/email.html |
||
36 | */ |
||
37 | public $pattern = '/^[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/'; |
||
38 | |||
39 | /** |
||
40 | * @var boolean whether to check the MX record for the email address. |
||
41 | * Defaults to false. To enable it, you need to make sure the PHP function 'checkdnsrr' |
||
42 | * exists in your PHP installation. |
||
43 | * Please note that this check may fail due to temporary problems even if email is deliverable. |
||
44 | */ |
||
45 | public $checkMX = false; |
||
46 | |||
47 | /** |
||
48 | * @var boolean whether to check port 25 for the email address. |
||
49 | * Defaults to false. To enable it, ensure that the PHP functions 'dns_get_record' and |
||
50 | * 'fsockopen' are available in your PHP installation. |
||
51 | * Please note that this check may fail due to temporary problems even if email is deliverable. |
||
52 | */ |
||
53 | public $checkPort = false; |
||
54 | |||
55 | /** |
||
56 | * @Label('{attribute} must be valid email address') |
||
57 | * @var string |
||
58 | */ |
||
59 | public $msgValid = ''; |
||
60 | |||
61 | /** |
||
62 | * @Label('Email domain "{domain}" does not exists') |
||
63 | * @var string |
||
64 | */ |
||
65 | public $msgDomain = ''; |
||
66 | |||
67 | /** |
||
68 | * @Label('Email service does not seem to be running at "{domain}"') |
||
69 | * @var string |
||
70 | */ |
||
71 | public $msgPort = ''; |
||
72 | |||
73 | 2 | public function isValid(AnnotatedInterface $model, $attribute) |
|
119 | |||
120 | /** |
||
121 | * Retrieves the list of MX records for $domain and checks if port 25 |
||
122 | * is opened on any of these. |
||
123 | * @param string $domain domain to be checked |
||
124 | * @return boolean true if a reachable MX server has been found |
||
125 | */ |
||
126 | protected function checkMxPorts($domain) |
||
151 | |||
152 | } |
||
153 |