本文整理汇总了PHP中Zend_Validate_Hostname::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Validate_Hostname::getErrors方法的具体用法?PHP Zend_Validate_Hostname::getErrors怎么用?PHP Zend_Validate_Hostname::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Validate_Hostname
的用法示例。
在下文中一共展示了Zend_Validate_Hostname::getErrors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isValid
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is a valid email address
* according to RFC2822
*
* @link http://www.ietf.org/rfc/rfc2822.txt RFC2822
* @link http://www.columbia.edu/kermit/ascii.html US-ASCII characters
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
// Split email address up
if (!preg_match('/^(.+)@([^@]+)$/', $valueString, $matches)) {
$this->_error(self::INVALID);
return false;
}
$this->_localPart = $matches[1];
$this->_hostname = $matches[2];
// Match hostname part
$hostnameResult = $this->hostnameValidator->setTranslator($this->getTranslator())->isValid($this->_hostname);
if (!$hostnameResult) {
$this->_error(self::INVALID_HOSTNAME);
// Get messages and errors from hostnameValidator
foreach ($this->hostnameValidator->getMessages() as $message) {
$this->_messages[] = $message;
}
foreach ($this->hostnameValidator->getErrors() as $error) {
$this->_errors[] = $error;
}
}
// MX check on hostname via dns_get_record()
if ($this->_validateMx) {
if ($this->validateMxSupported()) {
$result = dns_get_mx($this->_hostname, $mxHosts);
if (count($mxHosts) < 1) {
$hostnameResult = false;
$this->_error(self::INVALID_MX_RECORD);
}
} else {
/**
* MX checks are not supported by this system
* @see Zend_Validate_Exception
*/
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Internal error: MX checking not available on this system');
}
}
// First try to match the local part on the common dot-atom format
$localResult = false;
// Dot-atom characters are: 1*atext *("." 1*atext)
// atext: ALPHA / DIGIT / and "!", "#", "$", "%", "&", "'", "*",
// "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~"
$atext = 'a-zA-Z0-9\\x21\\x23\\x24\\x25\\x26\\x27\\x2a\\x2b\\x2d\\x2f\\x3d\\x3f\\x5e\\x5f\\x60\\x7b\\x7c\\x7d';
if (preg_match('/^[' . $atext . ']+(\\x2e+[' . $atext . ']+)*$/', $this->_localPart)) {
$localResult = true;
} else {
// Try quoted string format
// Quoted-string characters are: DQUOTE *([FWS] qtext/quoted-pair) [FWS] DQUOTE
// qtext: Non white space controls, and the rest of the US-ASCII characters not
// including "\" or the quote character
$noWsCtl = '\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f';
$qtext = $noWsCtl . '\\x21\\x23-\\x5b\\x5d-\\x7e';
$ws = '\\x20\\x09';
if (preg_match('/^\\x22([' . $ws . $qtext . '])*[$ws]?\\x22$/', $this->_localPart)) {
$localResult = true;
} else {
$this->_error(self::DOT_ATOM);
$this->_error(self::QUOTED_STRING);
$this->_error(self::INVALID_LOCAL_PART);
}
}
// If both parts valid, return true
if ($localResult && $hostnameResult) {
return true;
} else {
return false;
}
}
示例2: isValid
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is a valid email address
* according to RFC2822
*
* @link http://www.ietf.org/rfc/rfc2822.txt RFC2822
* @link http://www.columbia.edu/kermit/ascii.html US-ASCII characters
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$matches = array();
$length = true;
$this->_setValue($valueString);
// Split email address up and disallow '..'
if (strpos($valueString, '..') !== false or !preg_match('/^(.+)@([^@]+)$/', $valueString, $matches)) {
$this->_error(self::INVALID);
return false;
}
$this->_localPart = $matches[1];
$this->_hostname = $matches[2];
if (strlen($this->_localPart) > 64 || strlen($this->_hostname) > 255) {
$length = false;
$this->_error(self::LENGTH_EXCEEDED);
}
// Match hostname part
$hostnameResult = $this->hostnameValidator->setTranslator($this->getTranslator())->isValid($this->_hostname);
if (!$hostnameResult) {
$this->_error(self::INVALID_HOSTNAME);
// Get messages and errors from hostnameValidator
foreach ($this->hostnameValidator->getMessages() as $code => $message) {
$this->_messages[$code] = $message;
}
foreach ($this->hostnameValidator->getErrors() as $error) {
$this->_errors[] = $error;
}
} else {
if ($this->_validateMx) {
// MX check on hostname via dns_get_record()
if ($this->validateMxSupported()) {
$result = dns_get_mx($this->_hostname, $mxHosts);
if (count($mxHosts) < 1) {
// the address may can accept email even if there's no MX record but A or A6 or AAAA record found
if ($this->_deepMxCheck && $this->validateDnsSupported()) {
if ($this->isReservedIpAddress($this->_hostname)) {
$hostnameResult = false;
$this->_error(self::INVALID_NETWORK_SEGMENT);
} else {
if (checkdnsrr($this->_hostname, "A") === false && checkdnsrr($this->_hostname, "AAAA") === false && checkdnsrr($this->_hostname, "A6") === false) {
$hostnameResult = false;
$this->_error(self::INVALID_MX_RECORD);
}
}
} else {
$hostnameResult = false;
$this->_error(self::INVALID_MX_RECORD);
}
} else {
// must check every MX record for at least one valid address
if ($this->_deepMxCheck && $this->validateDnsSupported()) {
$hasOneValidAddress = false;
foreach ($mxHosts as $key => $hostname) {
if (!$this->isReservedIpAddress($hostname) && (checkdnsrr($hostname, "A") !== false || checkdnsrr($hostname, "AAAA") !== false || checkdnsrr($hostname, "A6") !== false)) {
$hasOneValidAddress = true;
break;
}
}
if ($hasOneValidAssress === false) {
$hostnameResult = false;
$this->_error(self::INVALID_MX_RECORD);
}
}
}
} else {
/**
* MX checks are not supported by this system
* @see Zend_Validate_Exception
*/
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Internal error: MX checking not available on this system');
}
}
}
// First try to match the local part on the common dot-atom format
$localResult = false;
// Dot-atom characters are: 1*atext *("." 1*atext)
// atext: ALPHA / DIGIT / and "!", "#", "$", "%", "&", "'", "*",
// "+", "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~"
$atext = 'a-zA-Z0-9\\x21\\x23\\x24\\x25\\x26\\x27\\x2a\\x2b\\x2d\\x2f\\x3d\\x3f\\x5e\\x5f\\x60\\x7b\\x7c\\x7d\\x7e';
if (preg_match('/^[' . $atext . ']+(\\x2e+[' . $atext . ']+)*$/', $this->_localPart)) {
$localResult = true;
} else {
// Try quoted string format
// Quoted-string characters are: DQUOTE *([FWS] qtext/quoted-pair) [FWS] DQUOTE
// qtext: Non white space controls, and the rest of the US-ASCII characters not
// including "\" or the quote character
$noWsCtl = '\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f';
//.........这里部分代码省略.........