|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This software package is licensed under AGPL or Commercial license. |
|
5
|
|
|
* |
|
6
|
|
|
* @package maslosoft/mangan |
|
7
|
|
|
* @licence AGPL or Commercial |
|
8
|
|
|
* @copyright Copyright (c) Piotr Masełkowski <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) Maslosoft |
|
10
|
|
|
* @copyright Copyright (c) Others as mentioned in code |
|
11
|
|
|
* @link https://maslosoft.com/mangan/ |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Maslosoft\Mangan\Annotations\Validators; |
|
15
|
|
|
|
|
16
|
|
|
use Maslosoft\Addendum\Helpers\ParamsExpander; |
|
17
|
|
|
use Maslosoft\Mangan\Meta\ValidatorMeta; |
|
18
|
|
|
use Maslosoft\Mangan\Validators\BuiltIn\EmailValidator; |
|
19
|
|
|
use Maslosoft\Mangan\Validators\Proxy\EmailProxy; |
|
20
|
|
|
use Maslosoft\Mangan\Validators\Traits\AllowEmpty; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* EmailValidator validates that the attribute value is a valid email address. |
|
24
|
|
|
* |
|
25
|
|
|
* @author Qiang Xue <[email protected]> |
|
26
|
|
|
* @version $Id$ |
|
27
|
|
|
* @package system.validators |
|
28
|
|
|
* @since 1.0 |
|
29
|
|
|
*/ |
|
30
|
|
|
class EmailValidatorAnnotation extends ValidatorAnnotation |
|
31
|
|
|
{ |
|
32
|
|
|
|
|
33
|
|
|
use AllowEmpty; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string the regular expression used to validate the attribute value. |
|
37
|
|
|
* @see http://www.regular-expressions.info/email.html |
|
38
|
|
|
*/ |
|
39
|
|
|
public $pattern = EmailValidator::EmailPattern; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var string the regular expression used to validate email addresses with the name part. |
|
43
|
|
|
* This property is used only when {@link allowName} is true. |
|
44
|
|
|
* @see allowName |
|
45
|
|
|
*/ |
|
46
|
|
|
public $fullPattern = EmailValidator::FullEmailPattern; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var boolean whether to allow name in the email address (e.g. "Qiang Xue <[email protected]>"). Defaults to false. |
|
50
|
|
|
* @see fullPattern |
|
51
|
|
|
*/ |
|
52
|
|
|
public $allowName = false; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var boolean whether to check the MX record for the email address. |
|
56
|
|
|
* Defaults to false. To enable it, you need to make sure the PHP function 'checkdnsrr' |
|
57
|
|
|
* exists in your PHP installation. |
|
58
|
|
|
*/ |
|
59
|
|
|
public $checkMX = false; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @var boolean whether to check port 25 for the email address. |
|
63
|
|
|
* Defaults to false. To enable it, ensure that the PHP functions 'dns_get_record' and |
|
64
|
|
|
* 'fsockopen' are available in your PHP installation. |
|
65
|
|
|
*/ |
|
66
|
|
|
public $checkPort = false; |
|
67
|
|
|
|
|
68
|
1 |
|
public function init() |
|
69
|
|
|
{ |
|
70
|
1 |
|
$this->proxy = EmailProxy::class; |
|
71
|
1 |
|
$this->getEntity()->validators[] = new ValidatorMeta(ParamsExpander::expand($this, [ |
|
72
|
1 |
|
'pattern', |
|
73
|
|
|
'fullPattern', |
|
74
|
|
|
'allowName', |
|
75
|
|
|
'checkMX', |
|
76
|
|
|
'checkPort', |
|
77
|
|
|
'allowEmpty', |
|
78
|
|
|
'message', |
|
79
|
|
|
'skipOnError', |
|
80
|
|
|
'on', |
|
81
|
|
|
'safe', |
|
82
|
|
|
'enableClientValidation', |
|
83
|
|
|
'except', |
|
84
|
|
|
'proxy' |
|
85
|
|
|
])); |
|
86
|
1 |
|
} |
|
87
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|