本文整理汇总了PHP中Zend_Validate_Hostname::isValid方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Validate_Hostname::isValid方法的具体用法?PHP Zend_Validate_Hostname::isValid怎么用?PHP Zend_Validate_Hostname::isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Validate_Hostname
的用法示例。
在下文中一共展示了Zend_Validate_Hostname::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isValid
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the $value is a valid url that starts with http(s)://
* and the hostname is a valid TLD
*
* @param string $value
* @throws Zend_Validate_Exception if a fatal error occurs for validation process
* @return boolean
*/
public function isValid($value)
{
if (!is_string($value)) {
$this->_error(self::INVALID_URL);
return false;
}
$this->_setValue($value);
//get a Zend_Uri_Http object for our URL, this will only accept http(s) schemes
try {
$uriHttp = Zend_Uri_Http::fromString($value);
} catch (Zend_Uri_Exception $e) {
$this->_error(self::INVALID_URL);
return false;
}
//if we have a valid URI then we check the hostname for valid TLDs, and not local urls
$hostnameValidator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_DNS); //do not allow local hostnames, this is the default
if (!$hostnameValidator->isValid($uriHttp->getHost())) {
$this->_error(self::INVALID_URL);
return false;
}
return true;
}
示例2: validateInstance
function validateInstance($instance)
{
if ($instance == 'www' || $instance == 'www.' || $instance == 'dev') {
$ret = false;
echo json_encode(array('exists' => $ret));
die;
}
// Check that the selected instance name is a valid standard host name
$validate = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_ALL);
if (!$validate->isValid($instance)) {
$ret = false;
echo json_encode(array('exists' => $ret));
die;
}
$cupid = new Cupid();
$cupid->init();
$exists = $cupid->instanceExists($instance);
if (!$exists) {
$ret = true;
echo json_encode(array('exists' => $ret));
} else {
$ret = false;
echo json_encode(array('exists' => $ret));
}
$cupid->disconnect();
}
示例3: 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)
{
$this->_messages = array();
// Split email address up
if (!preg_match('/^(.+)@([^@]+)$/', $value, $matches)) {
$this->_messages[] = "'{$value}' is not a valid email address in the basic format local-part@hostname";
return false;
}
$localPart = $matches[1];
$hostname = $matches[2];
/**
* @todo 0.9 ZF-42 implement basic MX check on hostname via dns_get_record()
*/
// Match hostname part
$hostnameResult = $this->_hostnameValidator->isValid($hostname);
if (!$hostnameResult) {
$this->_messages[] = "'{$hostname}' is not a valid hostname for email address '{$value}'";
// Get messages from hostnameValidator
foreach ($this->_hostnameValidator->getMessages() as $message) {
$this->_messages[] = $message;
}
}
// 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';
$atext .= '\\x3d\\x3f\\x5e\\x5f\\x60\\x7b\\x7c\\x7d';
if (preg_match('/^[' . $atext . ']+(\\x2e+[' . $atext . ']+)*$/', $localPart)) {
$localResult = true;
} else {
$this->_messages[] = "'{$localPart}' not matched against dot-atom format";
}
// If not matched, try quoted string format
if (!$localResult) {
// 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$/', $localPart)) {
$localResult = true;
} else {
$this->_messages[] = "'{$localPart}' not matched against quoted-string format";
}
}
if (!$localResult) {
$this->_messages[] = "'{$localPart}' is not a valid local part for email address '{$value}'";
}
// If both parts valid, return true
if ($localResult && $hostnameResult) {
return true;
} else {
return false;
}
}
示例4: validate
public function validate(array $attributes)
{
if (empty($attributes[$this->_attributeName])) {
return true;
}
$attributeValues = $attributes[$this->_attributeName];
switch ($this->_options) {
case 'URN':
$urnValidator = new EngineBlock_Validator_Urn();
foreach ($attributeValues as $attributeValue) {
if (!$urnValidator->validate($attributeValue)) {
$this->_messages[] = array(self::ERROR_ATTRIBUTE_VALIDATOR_URN, $this->_attributeName, $this->_options, $attributeValue);
return false;
}
}
break;
case 'HostName':
$hostnameValidator = new Zend_Validate_Hostname();
foreach ($attributeValues as $attributeValue) {
if (!$hostnameValidator->isValid($attributeValue)) {
$this->_messages[] = array(self::ERROR_ATTRIBUTE_VALIDATOR_HOSTNAME, $this->_attributeName, $this->_options, $attributeValue);
return false;
}
}
break;
case 'URL':
foreach ($attributeValues as $attributeValue) {
if (!Zend_Uri::check($attributeValue)) {
$this->_messages[] = array(self::ERROR_ATTRIBUTE_VALIDATOR_URL, $this->_attributeName, $this->_options, $attributeValue);
return false;
}
}
break;
case 'URI':
$uriValidator = new EngineBlock_Validator_Uri();
foreach ($attributeValues as $attributeValue) {
if (!$uriValidator->validate($attributeValue)) {
$this->_messages[] = array(self::ERROR_ATTRIBUTE_VALIDATOR_URI, $this->_attributeName, $this->_options, $attributeValue);
return false;
}
}
break;
case 'EmailAddress':
$emailValidator = new Zend_Validate_EmailAddress();
foreach ($attributeValues as $attributeValue) {
if (!$emailValidator->isValid($attributeValue)) {
$this->_messages[] = array(self::ERROR_ATTRIBUTE_VALIDATOR_EMAIL, $this->_attributeName, $this->_options, $attributeValue);
return false;
}
}
break;
default:
throw new EngineBlock_Exception("Unknown validate option '{$this->_options}' for attribute validation");
}
return true;
}
示例5: setHost
/**
* Set the Hostname / IP to connect to.
* @param string $host Hostname / IP of the Database.
* @return Couchdb_Config $this This main class for method chaining.
* @throws Couchdb_Exception_Parameter
*/
public function setHost($host)
{
$ip = new Zend_Validate_Ip();
$name = new Zend_Validate_Hostname();
if ($ip->isValid($host) xor $name->isValid($host)) {
throw new Couchdb_Exception_Parameter("Wrong Parameters, host must either be a valid hostname or an IP");
}
$this->_host = $host;
return $this;
}
示例6: testBasic
/**
* Ensures that the validator follows expected behavior
*
* @return void
*/
public function testBasic()
{
$valuesExpected = array(array(Zend_Validate_Hostname::ALLOW_IP, true, array('1.2.3.4', '10.0.0.1', '255.255.255.255')), array(Zend_Validate_Hostname::ALLOW_IP, false, array('0.0.0.0', '0.0.0.256')), array(Zend_Validate_Hostname::ALLOW_DNS, true, array('example.com', 'example.museum')), array(Zend_Validate_Hostname::ALLOW_DNS, false, array('localhost', 'localhost.localdomain', '1.2.3.4')), array(Zend_Validate_Hostname::ALLOW_LOCAL, true, array('localhost', 'localhost.localdomain', 'example.com')), array(Zend_Validate_Hostname::ALLOW_ALL, true, array('localhost', 'example.com', '1.2.3.4')));
foreach ($valuesExpected as $element) {
$validator = new Zend_Validate_Hostname($element[0]);
foreach ($element[2] as $input) {
$this->assertEquals($element[1], $validator->isValid($input));
}
}
}
示例7: _factory
protected function _factory($type, $userId, $userIp, $cache = true, $preview = null, $portals = null, $channels = null, $seriesId = null, $offset = 0, $limit = null, Zend_Date $start = null, Zend_Date $finish = null, $showId = null, $exclude = null, $searchTerm = null, $searchFilter = null, $transcript = null)
{
$validator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_DNS, true, false);
$userIp = $validator->isValid($userIp) ? $userIp : null;
unset($validator);
$start = $start ? strval($start) : null;
$finish = $finish ? strval($finish) : null;
$stmt = Zend_Registry::get('dbh')->proc('page_content_load');
$stmt->bindParam(':preview', $preview, PDO::PARAM_INT);
$stmt->bindParam(':portals', $portals, PDO::PARAM_INT);
$stmt->bindParam(':channels', $channels, PDO::PARAM_INT);
/*
$stmt->bindParam(':series', $seriesId, PDO::PARAM_INT);
$stmt->bindParam(':exclude', $exclude, PDO::PARAM_INT);
$stmt->bindParam(':show', $showId, PDO::PARAM_STR);
$stmt->bindParam(':start', $start, PDO::PARAM_STR);
$stmt->bindParam(':finish', $finish, PDO::PARAM_STR);
$stmt->bindParam(':search', $searchTerm, PDO::PARAM_STR);
$stmt->bindParam(':filter', $searchFilter, PDO::PARAM_STR);
$stmt->bindParam(':user', $user->id, PDO::PARAM_INT);
$stmt->bindParam(':ip', $userIp, PDO::PARAM_STR);
$stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
$stmt->bindParam(':limit', $limit, PDO::PARAM_INT);
$stmt->bindParam(':type', $type, PDO::PARAM_STR);
*/
$results = array();
try {
$stmt->execute();
$pageContent = array();
$rowCount = 0;
do {
$results[] = $stmt->fetchAll(Zend_Db::FETCH_OBJ);
} while ($stmt->nextRowset());
$stmt->closeCursor();
} catch (Zend_Db_Statement_Exception $e) {
if ('HYC00' == $stmt->errorCode()) {
$results[] = $stmt->fetchAll(Zend_Db::FETCH_OBJ);
}
}
foreach ($results as $rowset) {
foreach ($rowset as $row) {
if (isset($row->found_rows)) {
$rowCount = $row->found_rows;
continue;
} else {
$pageContent[] = Showcase_Content::factory($row, $cache);
}
}
}
$binds = array($user->id, $userIp, $offset, $limit, $type, $portals, $channels, $seriesId, $exclude, $showId, $start, $finish, $searchTerm, $searchFilter, $preview);
//print_r($binds);
//print_r($results);
//echo "CALL page_content_load(".implode($binds,',').")";
return array('contents' => $showId ? $pageContent[0] : $pageContent, 'rows' => !$rowCount ? count($pageContent) : $rowCount);
}
示例8: save
public function save()
{
$value = $this->getValue();
if (strlen($value) == 0) {
Mage::throwException(Mage::helper("mailup")->__("Please fill the admin console URL"));
}
$validator = new Zend_Validate_Hostname();
if (!$validator->isValid($value)) {
Mage::throwException(Mage::helper("mailup")->__("Admin console URL is not in the right format"));
}
return parent::save();
}
示例9: isValid
/**
* Returns true if and only if $value meets the validation requirements
*
* If $value fails validation, then this method returns false, and
* getMessages() will return an array of messages that explain why the
* validation failed.
*
* @param mixed $value
* @return boolean
* @throws \Zend_Valid_Exception If validation of $value is impossible
*/
public function isValid($value, $context = array())
{
$this->_setValue($value);
if ($value) {
try {
$uri = \Zend_Uri::factory($value);
// Check the host against the allowed values; delegated to \Zend_Filter.
$validate = new \Zend_Validate_Hostname(\Zend_Validate_Hostname::ALLOW_DNS | \Zend_Validate_Hostname::ALLOW_IP | \Zend_Validate_Hostname::ALLOW_LOCAL);
if (!$validate->isValid($uri->getHost())) {
foreach ($validate->getMessages() as $key => $msg) {
$this->_error($key);
}
return false;
}
if (function_exists('curl_init')) {
$ch = curl_init($value);
if (false === $ch) {
$this->_error(self::ERROR_URL_NOT_VALID);
return false;
}
// Authentication
// if ($usr) {
// curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// curl_setopt($ch, CURLOPT_USERPWD, $usr.':'.$pwd);
// }
// curl_setopt($ch, CURLOPT_FILETIME, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
/**
* @todo Unknown CA's should probably be imported...
*/
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$valid = curl_exec($ch);
if (!$valid) {
$this->_error(self::ERROR_SITE_NOT_FOUND);
}
// $return = curl_getinfo($ch, CURLINFO_FILETIME);
// \MUtil_Echo::r('Date at server: '.date('r', $return));
curl_close($ch);
return $valid;
} else {
return true;
}
} catch (\Exception $e) {
$this->_error(self::ERROR_URL_NOT_VALID);
$this->setMessage($e->getMessage(), self::ERROR_URL_NOT_VALID);
return false;
}
}
}
示例10: testIpValidatorMessagesShouldBeTranslated
/**
* @see ZF-2861
*/
public function testIpValidatorMessagesShouldBeTranslated()
{
require_once 'Zend/Validate/Ip.php';
$ipValidator = new Zend_Validate_Ip();
require_once 'Zend/Translate.php';
$translations = array('notIpAddress' => 'this is the IP error message');
$translator = new Zend_Translate('array', $translations);
$this->_validator->setTranslator($translator)->setIpValidator($ipValidator);
$this->_validator->isValid('0.239,512.777');
$messages = $ipValidator->getMessages();
$found = false;
foreach ($messages as $code => $message) {
if (array_key_exists($code, $translations)) {
$found = true;
break;
}
}
$this->assertTrue($found);
$this->assertEquals($translations[$code], $message);
}
示例11: isValid
/**
* Valid?
* @param $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
$uri = Zend_Uri::factory($value);
$uriSchema = $uri->getScheme();
try {
$uri->valid();
} catch (Exception $e) {
$this->_error(self::INVALID);
return false;
}
$validatorHostname = new Zend_Validate_Hostname(array('allow' => Zend_Validate_Hostname::ALLOW_DNS, 'idn' => true, 'tld' => false));
$protocol = !empty($uriSchema) ? $uriSchema . '://' : '';
$urlHostname = str_replace($protocol, "", $value);
if (!$validatorHostname->isValid($urlHostname)) {
$this->_error(self::INVALID_HOSTNAME);
return false;
}
return true;
}
示例12: isValid
/**
* Returns true if the value is a valid url that starts with http(s)://
* and the hostname is a valid TLD.
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
// Invalid if not string.
if (!is_string($value)) {
$this->_error(self::INVALID_URL);
return false;
}
$this->_setValue($value);
try {
// Try to parse a URL.
$uriHttp = Zend_Uri_Http::fromString($value);
} catch (Zend_Uri_Exception $e) {
// Invalid if not URL.
$this->_error(self::INVALID_URL);
return false;
}
$hostnameValidator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_LOCAL);
// Allow local URLs.
if (!$hostnameValidator->isValid($uriHttp->getHost())) {
$this->_error(self::INVALID_URL);
return false;
}
return true;
}
示例13: testDKSpecialChars
/**
* @ZF-12314
*/
public function testDKSpecialChars()
{
$this->assertTrue($this->_validator->isValid('testæøå.dk'));
}
示例14: createNewPassword
/**
*
*/
function createNewPassword(&$dbHandler, &$argsObj, &$userObj, $newPasswordSendMethod)
{
$op = new stdClass();
$op->user_feedback = '';
$op->new_password = '';
// Try to validate mail configuration
//
// From Zend Documentation
// You may find you also want to match IP addresses, Local hostnames, or a combination of all allowed types.
// This can be done by passing a parameter to Zend_Validate_Hostname when you instantiate it.
// The paramter should be an integer which determines what types of hostnames are allowed.
// You are encouraged to use the Zend_Validate_Hostname constants to do this.
// The Zend_Validate_Hostname constants are: ALLOW_DNS to allow only DNS hostnames, ALLOW_IP to allow IP addresses,
// ALLOW_LOCAL to allow local network names, and ALLOW_ALL to allow all three types.
//
$validator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_ALL);
$smtp_host = config_get('smtp_host');
$password_on_screen = $newPasswordSendMethod == 'display_on_screen';
if ($validator->isValid($smtp_host) || $password_on_screen) {
$dummy = resetPassword($dbHandler, $argsObj->user_id, $newPasswordSendMethod);
$op->user_feedback = $dummy['msg'];
$op->status = $dummy['status'];
$op->new_password = $dummy['password'];
if ($op->status >= tl::OK) {
logAuditEvent(TLS("audit_pwd_reset_requested", $userObj->login), "PWD_RESET", $argsObj->user_id, "users");
$op->user_feedback = lang_get('password_reseted');
if ($password_on_screen) {
$op->user_feedback = lang_get('password_set') . $dummy['password'];
}
} else {
$op->user_feedback = sprintf(lang_get('password_cannot_be_reseted_reason'), $op->user_feedback);
}
} else {
$op->status = tl::ERROR;
$op->user_feedback = lang_get('password_cannot_be_reseted_invalid_smtp_hostname');
}
return $op;
}
示例15: _assignGroups
protected function _assignGroups($credentials)
{
$options = array(0 => $this->language->get('text_select_a_group'));
if ($credentials) {
$validate = new Zend_Validate_Hostname();
if (!$validate->isValid($credentials['hostname'])) {
$this->error['warning'] = $this->language->get('error_please_provide_a_valid_hostname');
return $options;
}
$client = $this->_getClient($credentials['hostname'], $credentials['key']);
$params['enable'] = true;
$result = $this->_execute($client, 'getGroups', $params);
if ($result && $result['status']) {
foreach ($result['data'] as $item) {
$options[$item['id']] = $item['name'];
}
} else {
$this->error['warning'] = $this->language->get('error_invalid_api_key');
return $options;
}
}
return $options;
}