Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Zend_Validate_EmailAddress Class Reference
Inheritance diagram for Zend_Validate_EmailAddress:
Zend_Validate_Abstract Zend_Validate_Interface EmailAddress

Public Member Functions

 __construct ($options=array())
 
 getOptions ()
 
 setOptions (array $options=array())
 
 setMessage ($messageString, $messageKey=null)
 
 getHostnameValidator ()
 
 setHostnameValidator (Zend_Validate_Hostname $hostnameValidator=null, $allow=Zend_Validate_Hostname::ALLOW_DNS)
 
 validateMxSupported ()
 
 getValidateMx ()
 
 setValidateMx ($mx)
 
 getDeepMxCheck ()
 
 setDeepMxCheck ($deep)
 
 getDomainCheck ()
 
 setDomainCheck ($domain=true)
 
 isValid ($value)
 
- Public Member Functions inherited from Zend_Validate_Abstract
 getMessages ()
 
 getMessageVariables ()
 
 getMessageTemplates ()
 
 setMessage ($messageString, $messageKey=null)
 
 setMessages (array $messages)
 
 __get ($property)
 
 getErrors ()
 
 setObscureValue ($flag)
 
 getObscureValue ()
 
 setTranslator ($translator=null)
 
 getTranslator ()
 
 hasTranslator ()
 
 setDisableTranslator ($flag)
 
 translatorIsDisabled ()
 

Data Fields

const INVALID = 'emailAddressInvalid'
 
const INVALID_FORMAT = 'emailAddressInvalidFormat'
 
const INVALID_HOSTNAME = 'emailAddressInvalidHostname'
 
const INVALID_MX_RECORD = 'emailAddressInvalidMxRecord'
 
const INVALID_SEGMENT = 'emailAddressInvalidSegment'
 
const DOT_ATOM = 'emailAddressDotAtom'
 
const QUOTED_STRING = 'emailAddressQuotedString'
 
const INVALID_LOCAL_PART = 'emailAddressInvalidLocalPart'
 
const LENGTH_EXCEEDED = 'emailAddressLengthExceeded'
 

Protected Attributes

 $_messageTemplates
 
 $_invalidIp
 
 $_messageVariables
 
 $_hostname
 
 $_localPart
 
 $_options
 
- Protected Attributes inherited from Zend_Validate_Abstract
 $_value
 
 $_messageVariables = array()
 
 $_messageTemplates = array()
 
 $_messages = array()
 
 $_obscureValue = false
 
 $_errors = array()
 
 $_translator
 
 $_translatorDisabled = false
 

Additional Inherited Members

- Static Public Member Functions inherited from Zend_Validate_Abstract
static setDefaultTranslator ($translator=null)
 
static getDefaultTranslator ()
 
static hasDefaultTranslator ()
 
static getMessageLength ()
 
static setMessageLength ($length=-1)
 
- Protected Member Functions inherited from Zend_Validate_Abstract
 _createMessage ($messageKey, $value)
 
 _implodeRecursive (array $pieces)
 
 _error ($messageKey, $value=null)
 
 _setValue ($value)
 
- Static Protected Attributes inherited from Zend_Validate_Abstract
static $_defaultTranslator
 
static $_messageLength = -1
 

Detailed Description

Definition at line 38 of file EmailAddress.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = array())

Instantiates hostname validator for local use

The following option keys are supported: 'hostname' => A hostname validator, see Zend_Validate_Hostname 'allow' => Options for the hostname validator, see Zend_Validate_Hostname::ALLOW_* 'mx' => If MX check should be enabled, boolean 'deep' => If a deep MX check should be done, boolean

Parameters
array | string | Zend_Config$optionsOPTIONAL

Definition at line 137 of file EmailAddress.php.

138  {
139  if ($options instanceof Zend_Config) {
140  $options = $options->toArray();
141  } else if (!is_array($options)) {
142  $options = func_get_args();
143  $temp['allow'] = array_shift($options);
144  if (!empty($options)) {
145  $temp['mx'] = array_shift($options);
146  }
147 
148  if (!empty($options)) {
149  $temp['hostname'] = array_shift($options);
150  }
151 
152  $options = $temp;
153  }
154 
156  $this->setOptions($options);
157  }
setOptions(array $options=array())

Member Function Documentation

◆ getDeepMxCheck()

getDeepMxCheck ( )

Returns the set deepMxCheck option

Returns
boolean

Definition at line 304 of file EmailAddress.php.

305  {
306  return $this->_options['deep'];
307  }

◆ getDomainCheck()

getDomainCheck ( )

Returns the set domainCheck option

Returns
unknown

Definition at line 326 of file EmailAddress.php.

327  {
328  return $this->_options['domain'];
329  }

◆ getHostnameValidator()

getHostnameValidator ( )

Returns the set hostname validator

Returns
Zend_Validate_Hostname

Definition at line 236 of file EmailAddress.php.

237  {
238  return $this->_options['hostname'];
239  }

◆ getOptions()

getOptions ( )

Returns all set Options

Returns
array

Definition at line 164 of file EmailAddress.php.

165  {
166  return $this->_options;
167  }

◆ getValidateMx()

getValidateMx ( )

Returns the set validateMx option

Returns
boolean

Definition at line 274 of file EmailAddress.php.

275  {
276  return $this->_options['mx'];
277  }

◆ isValid()

isValid (   $value)

Defined by Zend_Validate_Interface

Returns true if and only if $value is a valid email address according to RFC2822

RFC2822 http://www.columbia.edu/kermit/ascii.html US-ASCII characters string $value boolean

Implements Zend_Validate_Interface.

Definition at line 532 of file EmailAddress.php.

533  {
534  if (!is_string($value)) {
535  $this->_error(self::INVALID);
536  return false;
537  }
538 
539  $matches = array();
540  $length = true;
541  $this->_setValue($value);
542 
543  // Split email address up and disallow '..'
544  if ((strpos($value, '..') !== false) or
545  (!preg_match('/^(.+)@([^@]+)$/', $value, $matches))) {
546  $this->_error(self::INVALID_FORMAT);
547  return false;
548  }
549 
550  $this->_localPart = $matches[1];
551  $this->_hostname = $matches[2];
552 
553  if ((strlen($this->_localPart) > 64) || (strlen($this->_hostname) > 255)) {
554  $length = false;
555  $this->_error(self::LENGTH_EXCEEDED);
556  }
557 
558  // Match hostname part
559  if ($this->_options['domain']) {
560  $hostname = $this->_validateHostnamePart();
561  }
562 
563  $local = $this->_validateLocalPart();
564 
565  // If both parts valid, return true
566  if ($local && $length) {
567  if (($this->_options['domain'] && $hostname) || !$this->_options['domain']) {
568  return true;
569  }
570  }
571 
572  return false;
573  }
_error($messageKey, $value=null)
Definition: Abstract.php:284
$value
Definition: gender.phtml:16

◆ setDeepMxCheck()

setDeepMxCheck (   $deep)

Set whether we check MX record should be a deep validation

Parameters
boolean$deepSet deep to true to perform a deep validation process for MX records
Returns
Zend_Validate_EmailAddress Provides a fluent inteface

Definition at line 315 of file EmailAddress.php.

316  {
317  $this->_options['deep'] = (bool) $deep;
318  return $this;
319  }

◆ setDomainCheck()

setDomainCheck (   $domain = true)

Sets if the domain should also be checked or only the local part of the email address

Parameters
boolean$domain
Returns
Zend_Validate_EmailAddress Provides a fluent inteface

Definition at line 338 of file EmailAddress.php.

339  {
340  $this->_options['domain'] = (boolean) $domain;
341  return $this;
342  }

◆ setHostnameValidator()

setHostnameValidator ( Zend_Validate_Hostname  $hostnameValidator = null,
  $allow = Zend_Validate_Hostname::ALLOW_DNS 
)
Parameters
Zend_Validate_Hostname$hostnameValidatorOPTIONAL
int$allowOPTIONAL
Returns
$this

Definition at line 246 of file EmailAddress.php.

247  {
248  if (!$hostnameValidator) {
249  $hostnameValidator = new Zend_Validate_Hostname($allow);
250  }
251 
252  $this->_options['hostname'] = $hostnameValidator;
253  $this->_options['allow'] = $allow;
254  return $this;
255  }

◆ setMessage()

setMessage (   $messageString,
  $messageKey = null 
)

Sets the validation failure message template for a particular key Adds the ability to set messages to the attached hostname validator

Parameters
string$messageString
string$messageKeyOPTIONAL
Returns
Zend_Validate_Abstract Provides a fluent interface
Exceptions
Zend_Validate_Exception

Definition at line 215 of file EmailAddress.php.

216  {
217  if ($messageKey === null) {
218  $this->_options['hostname']->setMessage($messageString);
219  parent::setMessage($messageString);
220  return $this;
221  }
222 
223  if (!isset($this->_messageTemplates[$messageKey])) {
224  $this->_options['hostname']->setMessage($messageString, $messageKey);
225  }
226 
227  $this->_messageTemplates[$messageKey] = $messageString;
228  return $this;
229  }

◆ setOptions()

setOptions ( array  $options = array())

Set options for the email validator

Parameters
array$options
Returns
Zend_Validate_EmailAddress Provides a fluent inteface

Definition at line 175 of file EmailAddress.php.

176  {
177  if (array_key_exists('messages', $options)) {
178  $this->setMessages($options['messages']);
179  }
180 
181  if (array_key_exists('hostname', $options)) {
182  if (array_key_exists('allow', $options)) {
183  $this->setHostnameValidator($options['hostname'], $options['allow']);
184  } else {
185  $this->setHostnameValidator($options['hostname']);
186  }
187  } elseif ($this->_options['hostname'] == null) {
188  $this->setHostnameValidator();
189  }
190 
191  if (array_key_exists('mx', $options)) {
192  $this->setValidateMx($options['mx']);
193  }
194 
195  if (array_key_exists('deep', $options)) {
196  $this->setDeepMxCheck($options['deep']);
197  }
198 
199  if (array_key_exists('domain', $options)) {
200  $this->setDomainCheck($options['domain']);
201  }
202 
203  return $this;
204  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
setHostnameValidator(Zend_Validate_Hostname $hostnameValidator=null, $allow=Zend_Validate_Hostname::ALLOW_DNS)
setMessages(array $messages)
Definition: Abstract.php:167

◆ setValidateMx()

setValidateMx (   $mx)

Set whether we check for a valid MX record via DNS

This only applies when DNS hostnames are validated

Parameters
boolean$mxSet allowed to true to validate for MX records, and false to not validate them
Exceptions
Zend_Validate_Exception
Returns
Zend_Validate_EmailAddress Provides a fluent inteface

Definition at line 288 of file EmailAddress.php.

289  {
290  if ((bool) $mx && !$this->validateMxSupported()) {
291  #require_once 'Zend/Validate/Exception.php';
292  throw new Zend_Validate_Exception('MX checking not available on this system');
293  }
294 
295  $this->_options['mx'] = (bool) $mx;
296  return $this;
297  }

◆ validateMxSupported()

validateMxSupported ( )

Whether MX checking via getmxrr is supported or not

This currently only works on UNIX systems

Returns
boolean

Definition at line 264 of file EmailAddress.php.

265  {
266  return function_exists('getmxrr');
267  }

Field Documentation

◆ $_hostname

$_hostname
protected

Definition at line 108 of file EmailAddress.php.

◆ $_invalidIp

$_invalidIp
protected
Initial value:
= array(
'0' => '0.0.0.0/8',
'10' => '10.0.0.0/8',
'100' => '100.64.0.0/10',
'127' => '127.0.0.0/8',
'169' => '169.254.0.0/16',
'172' => '172.16.0.0/12',
'192' => array(
'192.0.0.0/24',
'192.0.2.0/24',
'192.88.99.0/24',
'192.168.0.0/16'
),
'198' => '198.18.0.0/15',
'224' => '224.0.0.0/4',
'240' => '240.0.0.0/4'
)

Definition at line 79 of file EmailAddress.php.

◆ $_localPart

$_localPart
protected

Definition at line 113 of file EmailAddress.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::INVALID => "Invalid type given. String expected",
self::INVALID_FORMAT => "'%value%' is not a valid email address in the basic format local-part@hostname",
self::INVALID_HOSTNAME => "'%hostname%' is not a valid hostname for email address '%value%'",
self::INVALID_MX_RECORD => "'%hostname%' does not appear to have a valid MX record for the email address '%value%'",
self::INVALID_SEGMENT => "'%hostname%' is not in a routable network segment. The email address '%value%' should not be resolved from public network",
self::DOT_ATOM => "'%localPart%' can not be matched against dot-atom format",
self::QUOTED_STRING => "'%localPart%' can not be matched against quoted-string format",
self::INVALID_LOCAL_PART => "'%localPart%' is not a valid local part for email address '%value%'",
self::LENGTH_EXCEEDED => "'%value%' exceeds the allowed length",
)

Definition at line 53 of file EmailAddress.php.

◆ $_messageVariables

$_messageVariables
protected
Initial value:
= array(
'hostname' => '_hostname',
'localPart' => '_localPart'
)

Definition at line 100 of file EmailAddress.php.

◆ $_options

$_options
protected
Initial value:
= array(
'mx' => false,
'deep' => false,
'domain' => true,
'hostname' => null
)

Internal options array

Definition at line 118 of file EmailAddress.php.

◆ DOT_ATOM

const DOT_ATOM = 'emailAddressDotAtom'

Definition at line 45 of file EmailAddress.php.

◆ INVALID

const INVALID = 'emailAddressInvalid'

Definition at line 40 of file EmailAddress.php.

◆ INVALID_FORMAT

const INVALID_FORMAT = 'emailAddressInvalidFormat'

Definition at line 41 of file EmailAddress.php.

◆ INVALID_HOSTNAME

const INVALID_HOSTNAME = 'emailAddressInvalidHostname'

Definition at line 42 of file EmailAddress.php.

◆ INVALID_LOCAL_PART

const INVALID_LOCAL_PART = 'emailAddressInvalidLocalPart'

Definition at line 47 of file EmailAddress.php.

◆ INVALID_MX_RECORD

const INVALID_MX_RECORD = 'emailAddressInvalidMxRecord'

Definition at line 43 of file EmailAddress.php.

◆ INVALID_SEGMENT

const INVALID_SEGMENT = 'emailAddressInvalidSegment'

Definition at line 44 of file EmailAddress.php.

◆ LENGTH_EXCEEDED

const LENGTH_EXCEEDED = 'emailAddressLengthExceeded'

Definition at line 48 of file EmailAddress.php.

◆ QUOTED_STRING

const QUOTED_STRING = 'emailAddressQuotedString'

Definition at line 46 of file EmailAddress.php.


The documentation for this class was generated from the following file: