|
7 | 7 | */
|
8 | 8 | namespace Magento\Framework\Validator;
|
9 | 9 |
|
10 |
| -use Zend_Config; |
11 |
| - |
12 | 10 | class EmailAddress extends \Zend_Validate_EmailAddress implements \Magento\Framework\Validator\ValidatorInterface
|
13 | 11 | {
|
14 | 12 | /**
|
15 |
| - * Instantiates email validator for local use |
| 13 | + * Instantiates hostname validator for local use. |
| 14 | + * TLD validation is off by default. |
16 | 15 | *
|
17 | 16 | * The following option keys are supported:
|
18 | 17 | * 'hostname' => A hostname validator, see Zend_Validate_Hostname
|
19 | 18 | * 'allow' => Options for the hostname validator, see Zend_Validate_Hostname::ALLOW_*
|
20 | 19 | * 'mx' => If MX check should be enabled, boolean
|
21 | 20 | * 'deep' => If a deep MX check should be done, boolean
|
22 |
| - * 'tld' => If TLD validation should be done, boolean, default false |
23 | 21 | *
|
24 |
| - * @param array $options OPTIONAL |
| 22 | + * @param array|string|Zend_Config $options OPTIONAL |
25 | 23 | */
|
26 | 24 | public function __construct($options = [])
|
27 | 25 | {
|
28 |
| - if ($options instanceof Zend_Config) { |
29 |
| - $options = $options->toArray(); |
30 |
| - } elseif (!is_array($options)) { |
31 |
| - $options = func_get_args(); |
32 |
| - $temp['allow'] = array_shift($options); |
33 |
| - if (!empty($options)) { |
34 |
| - $temp['mx'] = array_shift($options); |
35 |
| - } |
36 |
| - |
37 |
| - if (!empty($options)) { |
38 |
| - $temp['hostname'] = array_shift($options); |
39 |
| - } |
40 |
| - |
41 |
| - if (!empty($options)) { |
42 |
| - $temp['tld'] = array_shift($options); |
43 |
| - } |
44 |
| - |
45 |
| - $options = $temp; |
46 |
| - } |
47 | 26 | parent::__construct($options);
|
48 | 27 |
|
49 |
| - $this->getHostnameValidator()->setValidateTld(array_key_exists('tld', $options) ? $options['tld'] : false); |
| 28 | + $this->getHostnameValidator()->setValidateTld(false); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Sets whether or not top-level domains should be validated |
| 33 | + * |
| 34 | + * @param bool $shouldValidate |
| 35 | + * @return void |
| 36 | + */ |
| 37 | + public function setValidateTld(bool $shouldValidate) |
| 38 | + { |
| 39 | + $this->getHostnameValidator()->setValidateTld($shouldValidate); |
50 | 40 | }
|
51 | 41 | }
|
0 commit comments