Zend Framework  1.12
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Zend_Validate_Hostname Class Reference

Public Member Functions

 __construct ($options=array())
 Sets validator options.
 
 getOptions ()
 Returns all set options.
 
 setOptions ($options)
 Sets the options for this validator.
 
 getIpValidator ()
 Returns the set ip validator.
 
 setIpValidator (Zend_Validate_Ip $ipValidator=null)
 
 getAllow ()
 Returns the allow option.
 
 setAllow ($allow)
 Sets the allow option.
 
 getValidateIdn ()
 Returns the set idn option.
 
 setValidateIdn ($allowed)
 Set whether IDN domains are validated.
 
 getValidateTld ()
 Returns the set tld option.
 
 setValidateTld ($allowed)
 Set whether the TLD element of a hostname is validated.
 
 isValid ($value)
 Defined by Zend_Validate_Interface.
 
- Public Member Functions inherited from Zend_Validate_Abstract
 getMessages ()
 Returns array of validation failure messages.
 
 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.
 
 getErrors ()
 Returns array of validation failure message codes.
 
 setObscureValue ($flag)
 Set flag indicating whether or not value should be obfuscated in messages.
 
 getObscureValue ()
 Retrieve flag indicating whether or not value should be obfuscated in messages.
 
 setTranslator ($translator=null)
 Set translation object.
 
 getTranslator ()
 Return translation object.
 
 hasTranslator ()
 Does this validator have its own specific translator?
 
 setDisableTranslator ($flag)
 Indicate whether or not translation should be disabled.
 
 translatorIsDisabled ()
 Is translation disabled?
 

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
 Allows Internet domain names (e.g., example.com)
 
const ALLOW_IP = 2
 Allows IP addresses.
 
const ALLOW_LOCAL = 4
 Allows local network names (e.g., localhost, www.localdomain)
 
const ALLOW_URI = 8
 Allows all types of hostnames.
 
const ALLOW_ALL = 15
 Allows all types of hostnames.
 

Protected Member Functions

 decodePunycode ($encoded)
 Decodes a punycode encoded string to it's original utf8 string In case of a decoding failure the original string is returned.
 
- Protected Member Functions inherited from Zend_Validate_Abstract
 _createMessage ($messageKey, $value)
 Constructs and returns a validation failure message with the given message key and value.
 
 _error ($messageKey, $value=null)
 
 _setValue ($value)
 Sets the value to be validated and clears the messages and errors arrays.
 

Protected Attributes

 $_messageTemplates
 
 $_messageVariables
 
 $_validTlds
 
 $_tld
 
 $_validIdns
 
 $_idnLength
 
 $_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)
 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 getMessageLength ()
 Returns the maximum allowed message length.
 
static setMessageLength ($length=-1)
 Sets the maximum allowed message length.
 
- Static Protected Attributes inherited from Zend_Validate_Abstract
static $_defaultTranslator
 
static $_messageLength = -1
 

Constructor & Destructor Documentation

__construct (   $options = array())

Sets validator options.

Parameters
integer$allowOPTIONAL Set what types of hostname to allow (default ALLOW_DNS)
boolean$validateIdnOPTIONAL Set whether IDN domains are validated (default true)
boolean$validateTldOPTIONAL Set whether the TLD element of a hostname is validated (default true)
Zend_Validate_Ip$ipValidatorOPTIONAL
Returns
void
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 In case of a decoding failure the original string is returned.

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

Returns the allow option.

Returns
integer
getIpValidator ( )

Returns the set ip validator.

Returns
Zend_Validate_Ip
getOptions ( )

Returns all set options.

Returns
array
getValidateIdn ( )

Returns the set idn option.

Returns
boolean
getValidateTld ( )

Returns the set tld option.

Returns
boolean
isValid (   $value)

Defined by Zend_Validate_Interface.

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

Parameters
string$value
Exceptions
Zend_Validate_Exceptionif a fatal error occurs for validation process
Returns
boolean

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

See Also
Zend_Validate_Hostname_Interface

Implements Zend_Validate_Interface.

setAllow (   $allow)

Sets the allow option.

Parameters
integer$allow
Returns
Zend_Validate_Hostname Provides a fluent interface
setIpValidator ( Zend_Validate_Ip  $ipValidator = null)
Parameters
Zend_Validate_Ip$ipValidatorOPTIONAL
Returns
void;
setOptions (   $options)

Sets the options for this validator.

Parameters
array$options
Returns
Zend_Validate_Hostname
setValidateIdn (   $allowed)

Set whether IDN domains are validated.

This only applies when DNS hostnames are validated

Parameters
boolean$allowedSet allowed to true to validate IDNs, and false to not validate them
setValidateTld (   $allowed)

Set whether the TLD element of a hostname is validated.

This only applies when DNS hostnames are validated

Parameters
boolean$allowedSet allowed to true to validate TLDs, and false to not validate them

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 => 20),
'公司' => array(1 => 20),
'网络' => array(1 => 20),
)
$_messageTemplates
protected
Initial value:
= array(
self::CANNOT_DECODE_PUNYCODE => "'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded",
self::INVALID => "Invalid type given. String expected",
self::INVALID_DASH => "'%value%' appears to be a DNS hostname but contains a dash in an invalid position",
self::INVALID_HOSTNAME => "'%value%' does not match the expected structure for a DNS hostname",
self::INVALID_HOSTNAME_SCHEMA => "'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'",
self::INVALID_LOCAL_NAME => "'%value%' does not appear to be a valid local network name",
self::INVALID_URI => "'%value%' does not appear to be a valid URI hostname",
self::IP_ADDRESS_NOT_ALLOWED => "'%value%' appears to be an IP address, but IP addresses are not allowed",
self::LOCAL_NAME_NOT_ALLOWED => "'%value%' appears to be a local network name but local network names are not allowed",
self::UNDECIPHERABLE_TLD => "'%value%' appears to be a DNS hostname but cannot extract TLD part",
self::UNKNOWN_TLD => "'%value%' 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,
'idn' => true,
'tld' => true,
'ip' => null
)
$_tld
protected
$_validIdns
protected
$_validTlds
protected
const ALLOW_ALL = 15

Allows all types of hostnames.

const ALLOW_DNS = 1

Allows Internet domain names (e.g., example.com)

const ALLOW_IP = 2

Allows IP addresses.

const ALLOW_LOCAL = 4

Allows local network names (e.g., localhost, www.localdomain)

const ALLOW_URI = 8

Allows all types of hostnames.

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'