Zend\Validator\Hostname
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.
Synopsis
class Hostname
extends AbstractValidator
{
- // constants
- 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;
- // members
- protected array $messageTemplates;
- protected array $messageVariables;
- protected array $validTlds;
- protected array $validIdns;
- protected array $idnLength;
- protected $tld;
- protected array $options;
- // Inherited members from AbstractValidator
- protected mixed $value;
- protected TranslatorInterface $defaultTranslator;
- protected string $defaultTranslatorTextDomain;
- protected integer $messageLength;
- protected array $abstractOptions;
- // methods
- public void __construct()
- public Ip getIpValidator()
- public Hostname; setIpValidator()
- public int getAllow()
- public Hostname setAllow()
- public bool getIdnCheck()
- public Hostname useIdnCheck()
- public bool getTldCheck()
- public Hostname useTldCheck()
- public bool isValid()
- protected string|false decodePunycode()
- // Inherited methods from AbstractValidator
- public void __construct()
- public mixed getOption()
- public array getOptions()
- public AbstractValidator setOptions()
- public array getMessages()
- public bool __invoke()
- public array getMessageVariables()
- public array getMessageTemplates()
- public AbstractValidator setMessage()
- public AbstractValidator setMessages()
- public mixed __get()
- protected string createMessage()
- protected void error()
- protected mixed getValue()
- protected void setValue()
- public AbstractValidator setValueObscured()
- public bool isValueObscured()
- public AbstractValidator setTranslator()
- public TranslatorInterface|null getTranslator()
- public bool hasTranslator()
- public AbstractValidator setTranslatorTextDomain()
- public string getTranslatorTextDomain()
- public static void setDefaultTranslator()
- public static TranslatorInterface|null getDefaultTranslator()
- public static bool hasDefaultTranslator()
- public static void setDefaultTranslatorTextDomain()
- public static string getDefaultTranslatorTextDomain()
- public AbstractValidator setTranslatorEnabled()
- public bool isTranslatorEnabled()
- public static int getMessageLength()
- public static void setMessageLength()
- protected string translateMessage()
Hierarchy
Extends
Constants
Name | Value |
---|---|
CANNOT_DECODE_PUNYCODE | 'hostnameCannotDecodePunycode' |
INVALID | 'hostnameInvalid' |
INVALID_DASH | 'hostnameDashCharacter' |
INVALID_HOSTNAME | 'hostnameInvalidHostname' |
INVALID_HOSTNAME_SCHEMA | 'hostnameInvalidHostnameSchema' |
INVALID_LOCAL_NAME | 'hostnameInvalidLocalName' |
INVALID_URI | 'hostnameInvalidUri' |
IP_ADDRESS_NOT_ALLOWED | 'hostnameIpAddressNotAllowed' |
LOCAL_NAME_NOT_ALLOWED | 'hostnameLocalNameNotAllowed' |
UNDECIPHERABLE_TLD | 'hostnameUndecipherableTld' |
UNKNOWN_TLD | 'hostnameUnknownTld' |
ALLOW_DNS | 1 |
ALLOW_IP | 2 |
ALLOW_LOCAL | 4 |
ALLOW_URI | 8 |
ALLOW_ALL | 15 |
Members
protected
- $abstractOptions
- $defaultTranslator
—
Zend\Validator\Translator\TranslatorInterface
Default translation object for all validate objects - $defaultTranslatorTextDomain
—
string
Default text domain to be used with translator - $idnLength
- $messageLength
—
int
Limits the maximum returned length of an error message - $messageTemplates — array
- $messageVariables — array
- $options
—
array
Options for the hostname validator - $tld
- $validIdns
—
array
Array for valid Idns - $validTlds
—
array
Array of valid top-level-domains - $value
—
mixed
The value to be validated
Methods
protected
- decodePunycode() — Decodes a punycode encoded string to it's original utf8 string Returns false in case of a decoding failure.
public
- __construct() — Sets validator options.
- getAllow() — Returns the allow option
- getIdnCheck() — Returns the set idn option
- getIpValidator() — Returns the set ip validator
- getTldCheck() — Returns the set tld option
- isValid() — Defined by Interface
- setAllow() — Sets the allow option
- setIpValidator()
- useIdnCheck() — Set whether IDN domains are validated
- useTldCheck() — Set whether the TLD element of a hostname is validated
Inherited from Zend\Validator\AbstractValidator
protected
- createMessage() — Constructs and returns a validation failure message with the given message key and value.
- error()
- getValue() — Returns the validation value
- setValue() — Sets the value to be validated and clears the messages and errors arrays
- translateMessage() — Translate a validation message
public
- __get() — Magic function returns the value of the requested property, if and only if it is the value or a message variable.
- __invoke() — Invoke as command
- getDefaultTranslator() — Get default translation object for all validate objects
- getDefaultTranslatorTextDomain() — Get default translation text domain for all validate objects
- getMessageLength() — Returns the maximum allowed message length
- getMessageTemplates() — Returns the message templates from the validator
- getMessageVariables() — Returns an array of the names of variables that are used in constructing validation failure messages
- getMessages() — Returns array of validation failure messages
- getOption() — Returns an option
- getOptions() — Returns all available options
- getTranslator() — Return translation object
- getTranslatorTextDomain() — Return the translation text domain
- hasDefaultTranslator() — Is there a default translation object set?
- hasTranslator() — Does this validator have its own specific translator?
- isTranslatorEnabled() — Is translation enabled?
- isValueObscured() — Retrieve flag indicating whether or not value should be obfuscated in messages
- setDefaultTranslator() — Set default translation object for all validate objects
- setDefaultTranslatorTextDomain() — Set default translation text domain for all validate objects
- setMessage() — Sets the validation failure message template for a particular key
- setMessageLength() — Sets the maximum allowed message length
- 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.
- setOptions() — Sets one or multiple options
- setTranslator() — Set translation object
- setTranslatorEnabled() — Indicate whether or not translation should be enabled
- setTranslatorTextDomain() — Set translation text domain
- setValueObscured() — Set flag indicating whether or not value should be obfuscated in messages