Zend Framework  2.4
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Hostname Class Reference

Please note there are two standalone test scripts for testing IDN characters due to problems with file encoding. More...

Public Member Functions

 __construct ($options=array())
 Sets validator options.
 
 getIpValidator ()
 Returns the set ip validator.
 
 setIpValidator (Ip $ipValidator=null)
 
 getAllow ()
 Returns the allow option.
 
 setAllow ($allow)
 Sets the allow option.
 
 getIdnCheck ()
 Returns the set idn option.
 
 useIdnCheck ($useIdnCheck)
 Set whether IDN domains are validated.
 
 getTldCheck ()
 Returns the set tld option.
 
 useTldCheck ($useTldCheck)
 Set whether the TLD element of a hostname is validated.
 
 isValid ($value)
 Defined by Interface.
 
- Public Member Functions inherited from AbstractValidator
 __construct ($options=null)
 Abstract constructor for all validators A validator should accept following parameters:
 
 getOption ($option)
 Returns an option.
 
 getOptions ()
 Returns all available options.
 
 setOptions ($options=array())
 Sets one or multiple options.
 
 getMessages ()
 Returns array of validation failure messages.
 
 __invoke ($value)
 Invoke as command.
 
 getMessageVariables ()
 Returns an array of the names of variables that are used in constructing validation failure messages.
 
 getMessageTemplates ()
 Returns the message templates from the validator.
 
 setMessage ($messageString, $messageKey=null)
 Sets the validation failure message template for a particular key.
 
 setMessages (array $messages)
 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.
 
 __get ($property)
 Magic function returns the value of the requested property, if and only if it is the value or a message variable.
 
 setValueObscured ($flag)
 Set flag indicating whether or not value should be obfuscated in messages.
 
 isValueObscured ()
 Retrieve flag indicating whether or not value should be obfuscated in messages.
 
 setTranslator (Translator\TranslatorInterface $translator=null, $textDomain=null)
 Set translation object.
 
 getTranslator ()
 Return translation object.
 
 hasTranslator ()
 Does this validator have its own specific translator?
 
 setTranslatorTextDomain ($textDomain= 'default')
 Set translation text domain.
 
 getTranslatorTextDomain ()
 Return the translation text domain.
 
 setTranslatorEnabled ($flag=true)
 Indicate whether or not translation should be enabled.
 
 isTranslatorEnabled ()
 Is translation enabled?
 
- Public Member Functions inherited from TranslatorAwareInterface
 setTranslator (TranslatorInterface $translator=null, $textDomain=null)
 Sets translator to use in helper.
 

Public Attributes

const CANNOT_DECODE_PUNYCODE = 'hostnameCannotDecodePunycode'
 
const INVALID = 'hostnameInvalid'
 
const INVALID_DASH = 'hostnameDashCharacter'
 
const INVALID_HOSTNAME = 'hostnameInvalidHostname'
 
const INVALID_HOSTNAME_SCHEMA = 'hostnameInvalidHostnameSchema'
 
const INVALID_LOCAL_NAME = 'hostnameInvalidLocalName'
 
const INVALID_URI = 'hostnameInvalidUri'
 
const IP_ADDRESS_NOT_ALLOWED = 'hostnameIpAddressNotAllowed'
 
const LOCAL_NAME_NOT_ALLOWED = 'hostnameLocalNameNotAllowed'
 
const UNDECIPHERABLE_TLD = 'hostnameUndecipherableTld'
 
const UNKNOWN_TLD = 'hostnameUnknownTld'
 
const ALLOW_DNS = 1
 
const ALLOW_IP = 2
 
const ALLOW_LOCAL = 4
 
const ALLOW_URI = 8
 
const ALLOW_ALL = 15
 

Protected Member Functions

 decodePunycode ($encoded)
 Decodes a punycode encoded string to it's original utf8 string Returns false in case of a decoding failure.
 
- Protected Member Functions inherited from AbstractValidator
 createMessage ($messageKey, $value)
 Constructs and returns a validation failure message with the given message key and value.
 
 error ($messageKey, $value=null)
 
 getValue ()
 Returns the validation value.
 
 setValue ($value)
 Sets the value to be validated and clears the messages and errors arrays.
 
 translateMessage ($messageKey, $message)
 Translate a validation message.
 

Protected Attributes

 $messageTemplates
 
 $messageVariables
 
 $validTlds
 
 $validIdns
 
 $idnLength
 
 $tld
 
 $options
 
- Protected Attributes inherited from AbstractValidator
 $value
 
 $abstractOptions
 

Additional Inherited Members

- Static Public Member Functions inherited from AbstractValidator
static setDefaultTranslator (Translator\TranslatorInterface $translator=null, $textDomain=null)
 Set default translation object for all validate objects.
 
static getDefaultTranslator ()
 Get default translation object for all validate objects.
 
static hasDefaultTranslator ()
 Is there a default translation object set?
 
static setDefaultTranslatorTextDomain ($textDomain= 'default')
 Set default translation text domain for all validate objects.
 
static getDefaultTranslatorTextDomain ()
 Get default translation text domain for all validate objects.
 
static getMessageLength ()
 Returns the maximum allowed message length.
 
static setMessageLength ($length=-1)
 Sets the maximum allowed message length.
 
- Static Protected Attributes inherited from AbstractValidator
static $defaultTranslator
 
static $defaultTranslatorTextDomain = 'default'
 
static $messageLength = -1
 

Detailed Description

Please note there are two standalone test scripts for testing IDN characters due to problems with file encoding.

The first is tests/Zend/Validator/HostnameTestStandalone.php which is designed to be run on the command line.

The second is tests/Zend/Validator/HostnameTestForm.php which is designed to be run via HTML to allow users to test entering UTF-8 characters in a form.

Constructor & Destructor Documentation

__construct (   $options = array())

Sets validator options.

Parameters
int$allowOPTIONAL Set what types of hostname to allow (default ALLOW_DNS)
bool$useIdnCheckOPTIONAL Set whether IDN domains are validated (default true)
bool$useTldCheckSet whether the TLD element of a hostname is validated (default true)
Ip$ipValidatorOPTIONAL
See Also
http://www.iana.org/cctld/specifications-policies-cctlds-01apr02.htm Technical Specifications for ccTLDs

Member Function Documentation

decodePunycode (   $encoded)
protected

Decodes a punycode encoded string to it's original utf8 string Returns false in case of a decoding failure.

Parameters
string$encodedPunycode encoded string to decode
Returns
string|false
getAllow ( )

Returns the allow option.

Returns
int
getIdnCheck ( )

Returns the set idn option.

Returns
bool
getIpValidator ( )

Returns the set ip validator.

Returns
Ip
getTldCheck ( )

Returns the set tld option.

Returns
bool
isValid (   $value)

Defined by Interface.

Returns true if and only if the $value is a valid hostname with respect to the current allow option

Parameters
string$value
Returns
bool

Match against IDN hostnames Note: Keep label regex short to avoid issues with long patterns when matching IDN hostnames

See Also
Hostname

Implements ValidatorInterface.

setAllow (   $allow)

Sets the allow option.

Parameters
int$allow
Returns
Hostname Provides a fluent interface
setIpValidator ( Ip  $ipValidator = null)
Parameters
Ip$ipValidatorOPTIONAL
Returns
Hostname;
useIdnCheck (   $useIdnCheck)

Set whether IDN domains are validated.

This only applies when DNS hostnames are validated

Parameters
bool$useIdnCheckSet to true to validate IDN domains
Returns
Hostname
useTldCheck (   $useTldCheck)

Set whether the TLD element of a hostname is validated.

This only applies when DNS hostnames are validated

Parameters
bool$useTldCheckSet to true to validate TLD elements
Returns
Hostname

Member Data Documentation

$idnLength
protected
Initial value:
= array(
'BIZ' => array(5 => 17, 11 => 15, 12 => 20),
'CN' => array(1 => 20),
'COM' => array(3 => 17, 5 => 20),
'HK' => array(1 => 15),
'INFO'=> array(4 => 17),
'KR' => array(1 => 17),
'NET' => array(3 => 17, 5 => 20),
'ORG' => array(6 => 17),
'TW' => array(1 => 20),
'امارات' => array(1 => 30),
'الاردن' => array(1 => 30),
'السعودية' => array(1 => 30),
'تونس' => array(1 => 30),
'مصر' => array(1 => 30),
'فلسطين' => array(1 => 30),
'شبكة' => array(1 => 30),
'中国' => array(1 => 20),
'中國' => array(1 => 20),
'香港' => array(1 => 20),
'台湾' => array(1 => 20),
'台灣' => array(1 => 20),
)
$messageTemplates
protected
Initial value:
= array(
self::CANNOT_DECODE_PUNYCODE => "The input appears to be a DNS hostname but the given punycode notation cannot be decoded",
self::INVALID => "Invalid type given. String expected",
self::INVALID_DASH => "The input appears to be a DNS hostname but contains a dash in an invalid position",
self::INVALID_HOSTNAME => "The input does not match the expected structure for a DNS hostname",
self::INVALID_HOSTNAME_SCHEMA => "The input appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'",
self::INVALID_LOCAL_NAME => "The input does not appear to be a valid local network name",
self::INVALID_URI => "The input does not appear to be a valid URI hostname",
self::IP_ADDRESS_NOT_ALLOWED => "The input appears to be an IP address, but IP addresses are not allowed",
self::LOCAL_NAME_NOT_ALLOWED => "The input appears to be a local network name but local network names are not allowed",
self::UNDECIPHERABLE_TLD => "The input appears to be a DNS hostname but cannot extract TLD part",
self::UNKNOWN_TLD => "The input appears to be a DNS hostname but cannot match TLD against known list",
)
$messageVariables
protected
Initial value:
= array(
'tld' => 'tld',
)
$options
protected
Initial value:
= array(
'allow' => self::ALLOW_DNS,
'useIdnCheck' => true,
'useTldCheck' => true,
'ipValidator' => null,
)
$tld
protected
$validIdns
protected
$validTlds
protected
const ALLOW_ALL = 15
const ALLOW_DNS = 1
const ALLOW_IP = 2
const ALLOW_LOCAL = 4
const ALLOW_URI = 8
const CANNOT_DECODE_PUNYCODE = 'hostnameCannotDecodePunycode'
const INVALID = 'hostnameInvalid'
const INVALID_DASH = 'hostnameDashCharacter'
const INVALID_HOSTNAME = 'hostnameInvalidHostname'
const INVALID_HOSTNAME_SCHEMA = 'hostnameInvalidHostnameSchema'
const INVALID_LOCAL_NAME = 'hostnameInvalidLocalName'
const INVALID_URI = 'hostnameInvalidUri'
const IP_ADDRESS_NOT_ALLOWED = 'hostnameIpAddressNotAllowed'
const LOCAL_NAME_NOT_ALLOWED = 'hostnameLocalNameNotAllowed'
const UNDECIPHERABLE_TLD = 'hostnameUndecipherableTld'
const UNKNOWN_TLD = 'hostnameUnknownTld'