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