Completed
Branch FET-9222-rest-api-writes (b69541)
by
unknown
25:55 queued 14:06
created

EmailValidationService::validate()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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