EmailAddress
extends AbstractValidator
in package
Table of Contents
Constants
- DOT_ATOM = 'emailAddressDotAtom'
- INVALID = 'emailAddressInvalid'
- INVALID_FORMAT = 'emailAddressInvalidFormat'
- INVALID_HOSTNAME = 'emailAddressInvalidHostname'
- INVALID_LOCAL_PART = 'emailAddressInvalidLocalPart'
- INVALID_MX_RECORD = 'emailAddressInvalidMxRecord'
- INVALID_SEGMENT = 'emailAddressInvalidSegment'
- LENGTH_EXCEEDED = 'emailAddressLengthExceeded'
- QUOTED_STRING = 'emailAddressQuotedString'
Properties
- $messageTemplates : array<string, string>
- $messageVariables : array<string, mixed>
- $options : array<string, mixed>
- $abstractOptions : AbstractOptions|array<string, mixed>
- $defaultTranslator : TranslatorInterface
- Default translation object for all validate objects
- $defaultTranslatorTextDomain : string
- Default text domain to be used with translator
- $hostname : string
- $localPart : string
- $messageLength : int
- Limits the maximum returned length of an error message
- $messageTemplates : array<string, string>
- $messageVariables : array<string|int, mixed>
- $mxRecord : array<string|int, mixed>
- Returns the found mx record information
- $options : array<string, mixed>
- Internal options array
- $value : mixed
- The value to be validated
Methods
- __construct() : mixed
- Instantiates hostname validator for local use
- __get() : mixed
- Magic function returns the value of the requested property, if and only if it is the value or a message variable.
- __invoke() : bool
- Invoke as command
- getAllow() : int
- Returns the allow option of the attached hostname validator
- getDeepMxCheck() : bool
- Returns the set deepMxCheck option
- getDefaultTranslator() : TranslatorInterface|null
- Get default translation object for all validate objects
- getDefaultTranslatorTextDomain() : string
- Get default translation text domain for all validate objects
- getDomainCheck() : bool
- Returns the set domainCheck option
- getHostnameValidator() : Hostname
- Returns the set hostname validator
- getMessageLength() : int
- Returns the maximum allowed message length
- getMessages() : array<string, string>
- Returns array of validation failure messages
- getMessageTemplates() : array<string, string>
- Returns the message templates from the validator
- getMessageVariables() : array<int, string>
- Returns an array of the names of variables that are used in constructing validation failure messages
- getMxCheck() : bool
- Returns the set validateMx option
- getMXRecord() : array<string|int, mixed>
- Returns the found MX Record information after validation including weight for further processing
- getOption() : mixed
- Returns an option
- getOptions() : array<string, mixed>
- Returns all available options
- getTranslator() : TranslatorInterface|null
- Return translation object
- getTranslatorTextDomain() : string
- Return the translation text domain
- hasDefaultTranslator() : bool
- Is there a default translation object set?
- hasTranslator() : bool
- Does this validator have its own specific translator?
- isMxSupported() : bool
- Whether MX checking via getmxrr is supported or not
- isTranslatorEnabled() : bool
- Is translation enabled?
- isValid() : bool
- Defined by Laminas\Validator\ValidatorInterface
- isValueObscured() : bool
- Retrieve flag indicating whether or not value should be obfuscated in messages
- setAllow() : $this
- Sets the allow option of the hostname validator to use
- setDefaultTranslator() : void
- Set default translation object for all validate objects
- setDefaultTranslatorTextDomain() : void
- Set default translation text domain for all validate objects
- setHostnameValidator() : $this
- setMessage() : AbstractValidator
- Sets the validation failure message template for a particular key Adds the ability to set messages to the attached hostname validator
- setMessageLength() : void
- Sets the maximum allowed message length
- setMessages() : $this
- Sets validation failure message templates given as an array, where the array keys are the message keys, and the array values are the message template strings.
- setOptions() : $this
- Sets one or multiple options
- setTranslator() : $this
- Set translation object
- setTranslatorEnabled() : $this
- Indicate whether or not translation should be enabled
- setTranslatorTextDomain() : $this
- Set translation text domain
- setValueObscured() : $this
- Set flag indicating whether or not value should be obfuscated in messages
- useDeepMxCheck() : $this
- Use deep validation for MX records
- useDomainCheck() : $this
- Sets if the domain should also be checked or only the local part of the email address
- useMxCheck() : $this
- Set whether we check for a valid MX record via DNS
- createMessage() : null|string
- Constructs and returns a validation failure message with the given message key and value.
- error() : void
- getValue() : mixed
- Returns the validation value
- idnToAscii() : string
- Safely convert UTF-8 encoded domain name to ASCII
- idnToUtf8() : string
- Safely convert ASCII encoded domain name to UTF-8
- isReserved() : bool
- Returns if the given host is reserved
- setValue() : void
- Sets the value to be validated and clears the messages and errors arrays
- splitEmailParts() : bool
- Splits the given value in hostname and local part of the email address
- translateMessage() : string
- Translate a validation message
- validateHostnamePart() : bool|array<string|int, string>
- Internal method to validate the hostname part of the email address
- validateInternationalizedLocalPart() : bool
- validateLocalPart() : bool
- Internal method to validate the local part of the email address
- validateMXRecords() : bool|array<string|int, string>
- Internal method to validate the servers MX records
Constants
DOT_ATOM
public
mixed
DOT_ATOM
= 'emailAddressDotAtom'
INVALID
public
mixed
INVALID
= 'emailAddressInvalid'
INVALID_FORMAT
public
mixed
INVALID_FORMAT
= 'emailAddressInvalidFormat'
INVALID_HOSTNAME
public
mixed
INVALID_HOSTNAME
= 'emailAddressInvalidHostname'
INVALID_LOCAL_PART
public
mixed
INVALID_LOCAL_PART
= 'emailAddressInvalidLocalPart'
INVALID_MX_RECORD
public
mixed
INVALID_MX_RECORD
= 'emailAddressInvalidMxRecord'
INVALID_SEGMENT
public
mixed
INVALID_SEGMENT
= 'emailAddressInvalidSegment'
LENGTH_EXCEEDED
public
mixed
LENGTH_EXCEEDED
= 'emailAddressLengthExceeded'
QUOTED_STRING
public
mixed
QUOTED_STRING
= 'emailAddressQuotedString'
Properties
$messageTemplates
public
array<string, string>
$messageTemplates
$messageVariables
public
array<string, mixed>
$messageVariables
$options
public
array<string, mixed>
$options
$abstractOptions
protected
AbstractOptions|array<string, mixed>
$abstractOptions
= [
'messages' => [],
// Array of validation failure messages
'messageTemplates' => [],
// Array of validation failure message templates
'messageVariables' => [],
// Array of additional variables available for validation failure messages
'translator' => null,
// Translation object to used -> Translator\TranslatorInterface
'translatorTextDomain' => null,
// Translation text domain
'translatorEnabled' => true,
// Is translation enabled?
'valueObscured' => false,
]
$defaultTranslator
Default translation object for all validate objects
protected
static TranslatorInterface
$defaultTranslator
$defaultTranslatorTextDomain
Default text domain to be used with translator
protected
static string
$defaultTranslatorTextDomain
= 'default'
$hostname
protected
string
$hostname
$localPart
protected
string
$localPart
$messageLength
Limits the maximum returned length of an error message
protected
static int
$messageLength
= -1
$messageTemplates
protected
array<string, string>
$messageTemplates
= [self::INVALID => "Invalid type given. String expected", self::INVALID_FORMAT => "The input is not a valid email address. Use the basic format local-part@hostname", self::INVALID_HOSTNAME => "'%hostname%' is not a valid hostname for the email address", self::INVALID_MX_RECORD => "'%hostname%' does not appear to have any valid MX or A records for the email address", self::INVALID_SEGMENT => "'%hostname%' is not in a routable network segment. The email address 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 the email address", self::LENGTH_EXCEEDED => "The input exceeds the allowed length"]
$messageVariables
protected
array<string|int, mixed>
$messageVariables
= ['hostname' => 'hostname', 'localPart' => 'localPart']
$mxRecord
Returns the found mx record information
protected
array<string|int, mixed>
$mxRecord
= []
$options
Internal options array
protected
array<string, mixed>
$options
= ['useMxCheck' => false, 'useDeepMxCheck' => false, 'useDomainCheck' => true, 'allow' => \Laminas\Validator\Hostname::ALLOW_DNS, 'strict' => true, 'hostnameValidator' => null]
$value
The value to be validated
protected
mixed
$value
Methods
__construct()
Instantiates hostname validator for local use
public
__construct([array<string|int, mixed>|Traversable $options = [] ]) : mixed
The following additional option keys are supported: 'hostnameValidator' => A hostname validator, see Laminas\Validator\Hostname 'allow' => Options for the hostname validator, see Laminas\Validator\Hostname::ALLOW_* 'strict' => Whether to adhere to strictest requirements in the spec 'useMxCheck' => If MX check should be enabled, boolean 'useDeepMxCheck' => If a deep MX check should be done, boolean
Parameters
- $options : array<string|int, mixed>|Traversable = []
-
OPTIONAL
__get()
Magic function returns the value of the requested property, if and only if it is the value or a message variable.
public
__get(string $property) : mixed
Parameters
- $property : string
Tags
__invoke()
Invoke as command
public
__invoke(mixed $value) : bool
Parameters
- $value : mixed
Return values
boolgetAllow()
Returns the allow option of the attached hostname validator
public
getAllow() : int
Return values
intgetDeepMxCheck()
Returns the set deepMxCheck option
public
getDeepMxCheck() : bool
Return values
boolgetDefaultTranslator()
Get default translation object for all validate objects
public
static getDefaultTranslator() : TranslatorInterface|null
Return values
TranslatorInterface|nullgetDefaultTranslatorTextDomain()
Get default translation text domain for all validate objects
public
static getDefaultTranslatorTextDomain() : string
Return values
stringgetDomainCheck()
Returns the set domainCheck option
public
getDomainCheck() : bool
Return values
boolgetHostnameValidator()
Returns the set hostname validator
public
getHostnameValidator() : Hostname
If was not previously set then lazy load a new one
Return values
HostnamegetMessageLength()
Returns the maximum allowed message length
public
static getMessageLength() : int
Return values
intgetMessages()
Returns array of validation failure messages
public
getMessages() : array<string, string>
Return values
array<string, string>getMessageTemplates()
Returns the message templates from the validator
public
getMessageTemplates() : array<string, string>
Return values
array<string, string>getMessageVariables()
Returns an array of the names of variables that are used in constructing validation failure messages
public
getMessageVariables() : array<int, string>
Return values
array<int, string>getMxCheck()
Returns the set validateMx option
public
getMxCheck() : bool
Return values
boolgetMXRecord()
Returns the found MX Record information after validation including weight for further processing
public
getMXRecord() : array<string|int, mixed>
Return values
array<string|int, mixed>getOption()
Returns an option
public
getOption(string $option) : mixed
Parameters
- $option : string
-
Option to be returned
Tags
Return values
mixed —Returned option
getOptions()
Returns all available options
public
getOptions() : array<string, mixed>
Return values
array<string, mixed> —Array with all available options
getTranslator()
Return translation object
public
getTranslator() : TranslatorInterface|null
Return values
TranslatorInterface|nullgetTranslatorTextDomain()
Return the translation text domain
public
getTranslatorTextDomain() : string
Return values
stringhasDefaultTranslator()
Is there a default translation object set?
public
static hasDefaultTranslator() : bool
Return values
boolhasTranslator()
Does this validator have its own specific translator?
public
hasTranslator() : bool
Return values
boolisMxSupported()
Whether MX checking via getmxrr is supported or not
public
isMxSupported() : bool
Return values
boolisTranslatorEnabled()
Is translation enabled?
public
isTranslatorEnabled() : bool
Return values
boolisValid()
Defined by Laminas\Validator\ValidatorInterface
public
isValid(string $value) : bool
Returns true if and only if $value is a valid email address according to RFC2822
Parameters
- $value : string
Tags
Return values
boolisValueObscured()
Retrieve flag indicating whether or not value should be obfuscated in messages
public
isValueObscured() : bool
Return values
boolsetAllow()
Sets the allow option of the hostname validator to use
public
setAllow(int $allow) : $this
Parameters
- $allow : int
Return values
$this —Provides a fluent interface
setDefaultTranslator()
Set default translation object for all validate objects
public
static setDefaultTranslator([TranslatorInterface|null $translator = null ][, string $textDomain = null ]) : void
Parameters
- $translator : TranslatorInterface|null = null
- $textDomain : string = null
-
(optional)
Tags
setDefaultTranslatorTextDomain()
Set default translation text domain for all validate objects
public
static setDefaultTranslatorTextDomain([string $textDomain = 'default' ]) : void
Parameters
- $textDomain : string = 'default'
setHostnameValidator()
public
setHostnameValidator([Hostname $hostnameValidator = null ]) : $this
Parameters
- $hostnameValidator : Hostname = null
-
OPTIONAL
Return values
$this —Provides a fluent interface
setMessage()
Sets the validation failure message template for a particular key Adds the ability to set messages to the attached hostname validator
public
setMessage(string $messageString[, string $messageKey = null ]) : AbstractValidator
Parameters
- $messageString : string
- $messageKey : string = null
-
OPTIONAL
Return values
AbstractValidator —Provides a fluent interface
setMessageLength()
Sets the maximum allowed message length
public
static setMessageLength([int $length = -1 ]) : void
Parameters
- $length : int = -1
setMessages()
Sets validation failure message templates given as an array, where the array keys are the message keys, and the array values are the message template strings.
public
setMessages(array<string, string> $messages) : $this
Parameters
- $messages : array<string, string>
Return values
$thissetOptions()
Sets one or multiple options
public
setOptions([array<string, mixed>|Traversable<string, mixed> $options = [] ]) : $this
Parameters
- $options : array<string, mixed>|Traversable<string, mixed> = []
-
Options to set
Tags
Return values
$this —Provides fluid interface
setTranslator()
Set translation object
public
setTranslator([TranslatorInterface|null $translator = null ][, string $textDomain = null ]) : $this
Parameters
- $translator : TranslatorInterface|null = null
-
[optional] translator. Default is null, which sets no translator.
- $textDomain : string = null
-
(optional)
Tags
Return values
$thissetTranslatorEnabled()
Indicate whether or not translation should be enabled
public
setTranslatorEnabled([bool $enabled = true ]) : $this
Parameters
- $enabled : bool = true
Return values
$thissetTranslatorTextDomain()
Set translation text domain
public
setTranslatorTextDomain([string $textDomain = 'default' ]) : $this
Parameters
- $textDomain : string = 'default'
Return values
$thissetValueObscured()
Set flag indicating whether or not value should be obfuscated in messages
public
setValueObscured(bool $flag) : $this
Parameters
- $flag : bool
Return values
$thisuseDeepMxCheck()
Use deep validation for MX records
public
useDeepMxCheck(bool $deep) : $this
Parameters
- $deep : bool
-
Set deep to true to perform a deep validation process for MX records
Return values
$this —Fluid Interface
useDomainCheck()
Sets if the domain should also be checked or only the local part of the email address
public
useDomainCheck([bool $domain = true ]) : $this
Parameters
- $domain : bool = true
Return values
$this —Fluid Interface
useMxCheck()
Set whether we check for a valid MX record via DNS
public
useMxCheck(bool $mx) : $this
This only applies when DNS hostnames are validated
Parameters
- $mx : bool
-
Set allowed to true to validate for MX records, and false to not validate them
Return values
$this —Fluid Interface
createMessage()
Constructs and returns a validation failure message with the given message key and value.
protected
createMessage(string $messageKey, string|array<string|int, mixed>|object $value) : null|string
Returns null if and only if $messageKey does not correspond to an existing template.
If a translator is available and a translation exists for $messageKey, the translation will be used.
Parameters
- $messageKey : string
- $value : string|array<string|int, mixed>|object
Return values
null|stringerror()
protected
error(string|null $messageKey[, null|string|array<string|int, mixed>|object $value = null ]) : void
Parameters
- $messageKey : string|null
- $value : null|string|array<string|int, mixed>|object = null
-
OPTIONAL
getValue()
Returns the validation value
protected
getValue() : mixed
Return values
mixed —Value to be validated
idnToAscii()
Safely convert UTF-8 encoded domain name to ASCII
protected
idnToAscii(string $email) : string
Parameters
- $email : string
-
the UTF-8 encoded email
Return values
stringidnToUtf8()
Safely convert ASCII encoded domain name to UTF-8
protected
idnToUtf8(string $email) : string
Parameters
- $email : string
-
the ASCII encoded email
Return values
stringisReserved()
Returns if the given host is reserved
protected
isReserved(string $host) : bool
The following addresses are seen as reserved '0.0.0.0/8', '10.0.0.0/8', '127.0.0.0/8' '100.64.0.0/10' '172.16.0.0/12' '198.18.0.0/15' '169.254.0.0/16', '192.168.0.0/16' '192.0.2.0/24', '192.88.99.0/24', '198.51.100.0/24', '203.0.113.0/24' '224.0.0.0/4', '240.0.0.0/4'
Parameters
- $host : string
Tags
Return values
bool —Returns false when minimal one of the given addresses is not reserved
setValue()
Sets the value to be validated and clears the messages and errors arrays
protected
setValue(mixed $value) : void
Parameters
- $value : mixed
splitEmailParts()
Splits the given value in hostname and local part of the email address
protected
splitEmailParts(string $value) : bool
Parameters
- $value : string
-
Email address to be split
Return values
bool —Returns false when the email can not be split
translateMessage()
Translate a validation message
protected
translateMessage(string $messageKey, string $message) : string
Parameters
- $messageKey : string
- $message : string
Return values
stringvalidateHostnamePart()
Internal method to validate the hostname part of the email address
protected
validateHostnamePart() : bool|array<string|int, string>
Tags
Return values
bool|array<string|int, string>validateInternationalizedLocalPart()
protected
validateInternationalizedLocalPart(string $localPart) : bool
Parameters
- $localPart : string
-
Address local part to validate.
Return values
boolvalidateLocalPart()
Internal method to validate the local part of the email address
protected
validateLocalPart() : bool
Return values
boolvalidateMXRecords()
Internal method to validate the servers MX records
protected
validateMXRecords() : bool|array<string|int, string>