1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\domain\services\validation\email; |
4
|
|
|
|
5
|
|
|
use EE_Registration_Config; |
6
|
|
|
use EventEspresso\core\services\loaders\Loader; |
7
|
|
|
|
8
|
|
|
defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed'); |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class EmailValidator |
14
|
|
|
* Loads the appropriate Email Validator as set in the Config |
15
|
|
|
* and then validates the supplied email address |
16
|
|
|
* |
17
|
|
|
* @package Event Espresso |
18
|
|
|
* @author Mike Nelson |
19
|
|
|
* @since $VID:$ |
20
|
|
|
*/ |
21
|
|
|
class EmailValidationService implements EmailValidatorInterface |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var EE_Registration_Config $registration_config |
26
|
|
|
*/ |
27
|
|
|
protected $registration_config; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Loader $loader |
31
|
|
|
*/ |
32
|
|
|
protected $loader; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* EmailValidationService constructor. |
38
|
|
|
* Accepts an \EE_Config as an argument. |
39
|
|
|
* |
40
|
|
|
* @param EE_Registration_Config $config |
41
|
|
|
* @param Loader $loader |
42
|
|
|
*/ |
43
|
|
|
public function __construct(EE_Registration_Config $config, Loader $loader) |
44
|
|
|
{ |
45
|
|
|
$this->registration_config = $config; |
46
|
|
|
$this->loader = $loader; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Validates the email address. If it's invalid, an EmailValidationException |
53
|
|
|
* is thrown that describes why its invalid. |
54
|
|
|
* |
55
|
|
|
* @param string $email_address |
56
|
|
|
* @return boolean |
57
|
|
|
* @throws EmailValidationException |
58
|
|
|
*/ |
59
|
|
|
public function validate($email_address) |
60
|
|
|
{ |
61
|
|
|
//pick the correct validator according to the config |
62
|
|
|
switch ($this->registration_config->email_validation_level) { |
63
|
|
|
case 'basic': |
64
|
|
|
$validator = $this->loader->getShared( |
65
|
|
|
'EventEspresso\core\domain\services\validation\email\strategies\Basic' |
66
|
|
|
); |
67
|
|
|
break; |
68
|
|
|
case 'i18n': |
69
|
|
|
$validator = $this->loader->getShared( |
70
|
|
|
'EventEspresso\core\domain\services\validation\email\strategies\International' |
71
|
|
|
) ; |
72
|
|
|
break; |
73
|
|
|
case 'i18n_dns': |
74
|
|
|
$validator = $this->loader->getShared( |
75
|
|
|
'EventEspresso\core\domain\services\validation\email\strategies\InternationalDNS' |
76
|
|
|
) ; |
77
|
|
|
break; |
78
|
|
|
case 'wp_default': |
79
|
|
|
default: |
80
|
|
|
$validator = $this->loader->getShared( |
81
|
|
|
'EventEspresso\core\domain\services\validation\email\strategies\WordPress' |
82
|
|
|
) ; |
83
|
|
|
break; |
84
|
|
|
} |
85
|
|
|
return $validator->validate($email_address); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
// End of file EmailValidator.php |
91
|
|
|
// Location: core\services\validation/EmailValidator.php |
92
|
|
|
|