début de script pour fusionner les RSS des strips et les annonces sur le forum

This commit is contained in:
nojhan 2008-04-26 21:33:55 +00:00
commit d45e9d721f
66 changed files with 12583 additions and 0 deletions

346
Zend/Validate/Abstract.php Normal file
View file

@ -0,0 +1,346 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Abstract.php 8113 2008-02-18 13:15:27Z matthew $
*/
/**
* @see Zend_Validate_Interface
*/
require_once 'Zend/Validate/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Validate_Abstract implements Zend_Validate_Interface
{
/**
* The value to be validated
*
* @var mixed
*/
protected $_value;
/**
* Additional variables available for validation failure messages
*
* @var array
*/
protected $_messageVariables = array();
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array();
/**
* Array of validation failure messages
*
* @var array
*/
protected $_messages = array();
/**
* Flag indidcating whether or not value should be obfuscated in error
* messages
* @var bool
*/
protected $_obscureValue = false;
/**
* Array of validation failure message codes
*
* @var array
* @deprecated Since 1.5.0
*/
protected $_errors = array();
/**
* Translation object
* @var Zend_Translate
*/
protected $_translator;
/**
* Default translation object for all validate objects
* @var Zend_Translate
*/
protected static $_defaultTranslator;
/**
* Returns array of validation failure messages
*
* @return array
*/
public function getMessages()
{
return $this->_messages;
}
/**
* Returns an array of the names of variables that are used in constructing validation failure messages
*
* @return array
*/
public function getMessageVariables()
{
return array_keys($this->_messageVariables);
}
/**
* Sets the validation failure message template for a particular key
*
* @param string $messageString
* @param string $messageKey OPTIONAL
* @return Zend_Validate_Abstract Provides a fluent interface
* @throws Zend_Validate_Exception
*/
public function setMessage($messageString, $messageKey = null)
{
if ($messageKey === null) {
$keys = array_keys($this->_messageTemplates);
$messageKey = current($keys);
}
if (!isset($this->_messageTemplates[$messageKey])) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("No message template exists for key '$messageKey'");
}
$this->_messageTemplates[$messageKey] = $messageString;
return $this;
}
/**
* 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.
*
* @param array $messages
* @return Zend_Validate_Abstract
*/
public function setMessages(array $messages)
{
foreach ($messages as $key => $message) {
$this->setMessage($message, $key);
}
return $this;
}
/**
* Magic function returns the value of the requested property, if and only if it is the value or a
* message variable.
*
* @param string $property
* @return mixed
* @throws Zend_Validate_Exception
*/
public function __get($property)
{
if ($property == 'value') {
return $this->_value;
}
if (array_key_exists($property, $this->_messageVariables)) {
return $this->{$this->_messageVariables[$property]};
}
/**
* @see Zend_Validate_Exception
*/
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("No property exists by the name '$property'");
}
/**
* Constructs and returns a validation failure message with the given message key and value.
*
* Returns null if and only if $messageKey does not correspond to an existing template.
*
* If a translator is available and a translation exists for $messageKey,
* the translation will be used.
*
* @param string $messageKey
* @param string $value
* @return string
*/
protected function _createMessage($messageKey, $value)
{
if (!isset($this->_messageTemplates[$messageKey])) {
return null;
}
$message = $this->_messageTemplates[$messageKey];
if (null !== ($translator = $this->getTranslator())) {
if ($translator->isTranslated($messageKey)) {
$message = $translator->translate($messageKey);
}
}
if ($this->getObscureValue()) {
$value = str_repeat('*', strlen($value));
}
$message = str_replace('%value%', (string) $value, $message);
foreach ($this->_messageVariables as $ident => $property) {
$message = str_replace("%$ident%", $this->$property, $message);
}
return $message;
}
/**
* @param string $messageKey OPTIONAL
* @param string $value OPTIONAL
* @return void
*/
protected function _error($messageKey = null, $value = null)
{
if ($messageKey === null) {
$keys = array_keys($this->_messageTemplates);
$messageKey = current($keys);
}
if ($value === null) {
$value = $this->_value;
}
$this->_errors[] = $messageKey;
$this->_messages[$messageKey] = $this->_createMessage($messageKey, $value);
}
/**
* Sets the value to be validated and clears the messages and errors arrays
*
* @param mixed $value
* @return void
*/
protected function _setValue($value)
{
$this->_value = $value;
$this->_messages = array();
$this->_errors = array();
}
/**
* Returns array of validation failure message codes
*
* @return array
* @deprecated Since 1.5.0
*/
public function getErrors()
{
return $this->_errors;
}
/**
* Set flag indicating whether or not value should be obfuscated in messages
*
* @param bool $flag
* @return Zend_Validate_Abstract
*/
public function setObscureValue($flag)
{
$this->_obscureValue = (bool) $flag;
return $this;
}
/**
* Retrieve flag indicating whether or not value should be obfuscated in
* messages
*
* @return bool
*/
public function getObscureValue()
{
return $this->_obscureValue;
}
/**
* Set translation object
*
* @param Zend_Translate|Zend_Translate_Adapter|null $translator
* @return Zend_Validate_Abstract
*/
public function setTranslator($translator = null)
{
if ((null === $translator) || ($translator instanceof Zend_Translate_Adapter)) {
$this->_translator = $translator;
} elseif ($translator instanceof Zend_Translate) {
$this->_translator = $translator->getAdapter();
} else {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Invalid translator specified');
}
return $this;
}
/**
* Return translation object
*
* @return Zend_Translate_Adapter|null
*/
public function getTranslator()
{
if (null === $this->_translator) {
return self::getDefaultTranslator();
}
return $this->_translator;
}
/**
* Set default translation object for all validate objects
*
* @param Zend_Translate|Zend_Translate_Adapter|null $translator
* @return void
*/
public static function setDefaultTranslator($translator = null)
{
if ((null === $translator) || ($translator instanceof Zend_Translate_Adapter)) {
self::$_defaultTranslator = $translator;
} elseif ($translator instanceof Zend_Translate) {
self::$_defaultTranslator = $translator->getAdapter();
} else {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Invalid translator specified');
}
}
/**
* Get default translation object for all validate objects
*
* @return Zend_Translate_Adapter|null
*/
public static function getDefaultTranslator()
{
if (null === self::$_defaultTranslator) {
require_once 'Zend/Registry.php';
if (Zend_Registry::isRegistered('Zend_Translate')) {
$translator = Zend_Registry::get('Zend_Translate');
if ($translator instanceof Zend_Translate_Adapter) {
return $translator;
} elseif ($translator instanceof Zend_Translate) {
return $translator->getAdapter();
}
}
}
return self::$_defaultTranslator;
}
}

120
Zend/Validate/Alnum.php Normal file
View file

@ -0,0 +1,120 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Alnum.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Alnum extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value contains non-alphabetic or non-digit characters
*/
const NOT_ALNUM = 'notAlnum';
/**
* Validation failure message key for when the value is an empty string
*/
const STRING_EMPTY = 'stringEmpty';
/**
* Whether to allow white space characters; off by default
*
* @var boolean
*/
public $allowWhiteSpace;
/**
* Alphanumeric filter used for validation
*
* @var Zend_Filter_Alnum
*/
protected static $_filter = null;
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::NOT_ALNUM => "'%value%' has not only alphabetic and digit characters",
self::STRING_EMPTY => "'%value%' is an empty string"
);
/**
* Sets default option values for this instance
*
* @param boolean $allowWhiteSpace
* @return void
*/
public function __construct($allowWhiteSpace = false)
{
$this->allowWhiteSpace = (boolean) $allowWhiteSpace;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value contains only alphabetic and digit characters
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if ('' === $valueString) {
$this->_error(self::STRING_EMPTY);
return false;
}
if (null === self::$_filter) {
/**
* @see Zend_Filter_Alnum
*/
require_once 'Zend/Filter/Alnum.php';
self::$_filter = new Zend_Filter_Alnum();
}
self::$_filter->allowWhiteSpace = $this->allowWhiteSpace;
if ($valueString !== self::$_filter->filter($valueString)) {
$this->_error(self::NOT_ALNUM);
return false;
}
return true;
}
}

120
Zend/Validate/Alpha.php Normal file
View file

@ -0,0 +1,120 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Alpha.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Alpha extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value contains non-alphabetic characters
*/
const NOT_ALPHA = 'notAlpha';
/**
* Validation failure message key for when the value is an empty string
*/
const STRING_EMPTY = 'stringEmpty';
/**
* Whether to allow white space characters; off by default
*
* @var boolean
*/
public $allowWhiteSpace;
/**
* Alphabetic filter used for validation
*
* @var Zend_Filter_Alpha
*/
protected static $_filter = null;
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::NOT_ALPHA => "'%value%' has not only alphabetic characters",
self::STRING_EMPTY => "'%value%' is an empty string"
);
/**
* Sets default option values for this instance
*
* @param boolean $allowWhiteSpace
* @return void
*/
public function __construct($allowWhiteSpace = false)
{
$this->allowWhiteSpace = (boolean) $allowWhiteSpace;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value contains only alphabetic characters
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if ('' === $valueString) {
$this->_error(self::STRING_EMPTY);
return false;
}
if (null === self::$_filter) {
/**
* @see Zend_Filter_Alpha
*/
require_once 'Zend/Filter/Alpha.php';
self::$_filter = new Zend_Filter_Alpha();
}
self::$_filter->allowWhiteSpace = $this->allowWhiteSpace;
if ($valueString !== self::$_filter->filter($valueString)) {
$this->_error(self::NOT_ALPHA);
return false;
}
return true;
}
}

99
Zend/Validate/Barcode.php Normal file
View file

@ -0,0 +1,99 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Barcode.php 8211 2008-02-20 14:29:24Z darby $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Barcode extends Zend_Validate_Abstract
{
/**
* Barcode validator
*
* @var Zend_Validate_Abstract
*/
protected $_barcodeValidator;
/**
* Generates the standard validator object
*
* @param string $barcodeType - Barcode validator to use
* @return void
* @throws Zend_Validate_Exception
*/
public function __construct($barcodeType)
{
$this->setType($barcodeType);
}
/**
* Sets a new barcode validator
*
* @param string $barcodeType - Barcode validator to use
* @return void
* @throws Zend_Validate_Exception
*/
public function setType($barcodeType)
{
switch (strtolower($barcodeType)) {
case 'upc':
case 'upc-a':
$className = 'UpcA';
break;
case 'ean13':
case 'ean-13':
$className = 'Ean13';
break;
default:
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("Barcode type '$barcodeType' is not supported'");
break;
}
require_once 'Zend/Validate/Barcode/' . $className . '.php';
$class = 'Zend_Validate_Barcode_' . $className;
$this->_barcodeValidator = new $class;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value contains a valid barcode
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
return call_user_func(array($this->_barcodeValidator, 'isValid'), $value);
}
}

View file

@ -0,0 +1,100 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Ean13.php 8210 2008-02-20 14:09:05Z andries $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Barcode_Ean13 extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value is
* an invalid barcode
*/
const INVALID = 'invalid';
/**
* Validation failure message key for when the value is
* not 13 characters long
*/
const INVALID_LENGTH = 'invalidLength';
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::INVALID => "'%value%' is an invalid EAN-13 barcode",
self::INVALID_LENGTH => "'%value%' should be 13 characters",
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value contains a valid barcode
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if (strlen($valueString) !== 13) {
$this->_error(self::INVALID_LENGTH);
return false;
}
$barcode = strrev(substr($valueString, 0, -1));
$oddSum = 0;
$evenSum = 0;
for ($i = 0; $i < 12; $i++) {
if ($i % 2 === 0) {
$oddSum += $barcode[$i] * 3;
} elseif ($i % 2 === 1) {
$evenSum += $barcode[$i];
}
}
$calculation = ($oddSum + $evenSum) % 10;
$checksum = ($calculation === 0) ? 0 : 10 - $calculation;
if ($valueString[12] != $checksum) {
$this->_error(self::INVALID);
return false;
}
return true;
}
}

View file

@ -0,0 +1,100 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: UpcA.php 8210 2008-02-20 14:09:05Z andries $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Barcode_UpcA extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value is
* an invalid barcode
*/
const INVALID = 'invalid';
/**
* Validation failure message key for when the value is
* not 12 characters long
*/
const INVALID_LENGTH = 'invalidLength';
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::INVALID => "'%value%' is an invalid UPC-A barcode",
self::INVALID_LENGTH => "'%value%' should be 12 characters",
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value contains a valid barcode
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if (strlen($valueString) !== 12) {
$this->_error(self::INVALID_LENGTH);
return false;
}
$barcode = substr($valueString, 0, -1);
$oddSum = 0;
$evenSum = 0;
for ($i = 0; $i < 11; $i++) {
if ($i % 2 === 0) {
$oddSum += $barcode[$i] * 3;
} elseif ($i % 2 === 1) {
$evenSum += $barcode[$i];
}
}
$calculation = ($oddSum + $evenSum) % 10;
$checksum = ($calculation === 0) ? 0 : 10 - $calculation;
if ($valueString[11] != $checksum) {
$this->_error(self::INVALID);
return false;
}
return true;
}
}

200
Zend/Validate/Between.php Normal file
View file

@ -0,0 +1,200 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Between.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Between extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value is not between the min and max, inclusively
*/
const NOT_BETWEEN = 'notBetween';
/**
* Validation failure message key for when the value is not strictly between the min and max
*/
const NOT_BETWEEN_STRICT = 'notBetweenStrict';
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::NOT_BETWEEN => "'%value%' is not between '%min%' and '%max%', inclusively",
self::NOT_BETWEEN_STRICT => "'%value%' is not strictly between '%min%' and '%max%'"
);
/**
* Additional variables available for validation failure messages
*
* @var array
*/
protected $_messageVariables = array(
'min' => '_min',
'max' => '_max'
);
/**
* Minimum value
*
* @var mixed
*/
protected $_min;
/**
* Maximum value
*
* @var mixed
*/
protected $_max;
/**
* Whether to do inclusive comparisons, allowing equivalence to min and/or max
*
* If false, then strict comparisons are done, and the value may equal neither
* the min nor max options
*
* @var boolean
*/
protected $_inclusive;
/**
* Sets validator options
*
* @param mixed $min
* @param mixed $max
* @param boolean $inclusive
* @return void
*/
public function __construct($min, $max, $inclusive = true)
{
$this->setMin($min)
->setMax($max)
->setInclusive($inclusive);
}
/**
* Returns the min option
*
* @return mixed
*/
public function getMin()
{
return $this->_min;
}
/**
* Sets the min option
*
* @param mixed $min
* @return Zend_Validate_Between Provides a fluent interface
*/
public function setMin($min)
{
$this->_min = $min;
return $this;
}
/**
* Returns the max option
*
* @return mixed
*/
public function getMax()
{
return $this->_max;
}
/**
* Sets the max option
*
* @param mixed $max
* @return Zend_Validate_Between Provides a fluent interface
*/
public function setMax($max)
{
$this->_max = $max;
return $this;
}
/**
* Returns the inclusive option
*
* @return boolean
*/
public function getInclusive()
{
return $this->_inclusive;
}
/**
* Sets the inclusive option
*
* @param boolean $inclusive
* @return Zend_Validate_Between Provides a fluent interface
*/
public function setInclusive($inclusive)
{
$this->_inclusive = $inclusive;
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is between min and max options, inclusively
* if inclusive option is true.
*
* @param mixed $value
* @return boolean
*/
public function isValid($value)
{
$this->_setValue($value);
if ($this->_inclusive) {
if ($this->_min > $value || $value > $this->_max) {
$this->_error(self::NOT_BETWEEN);
return false;
}
} else {
if ($this->_min >= $value || $value >= $this->_max) {
$this->_error(self::NOT_BETWEEN_STRICT);
return false;
}
}
return true;
}
}

111
Zend/Validate/Ccnum.php Normal file
View file

@ -0,0 +1,111 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Ccnum.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Ccnum extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value is not of valid length
*/
const LENGTH = 'ccnumLength';
/**
* Validation failure message key for when the value fails the mod-10 checksum
*/
const CHECKSUM = 'ccnumChecksum';
/**
* Digits filter for input
*
* @var Zend_Filter_Digits
*/
protected static $_filter = null;
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::LENGTH => "'%value%' must contain between 13 and 19 digits",
self::CHECKSUM => "Luhn algorithm (mod-10 checksum) failed on '%value%'"
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value follows the Luhn algorithm (mod-10 checksum)
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$this->_setValue($value);
if (null === self::$_filter) {
/**
* @see Zend_Filter_Digits
*/
require_once 'Zend/Filter/Digits.php';
self::$_filter = new Zend_Filter_Digits();
}
$valueFiltered = self::$_filter->filter($value);
$length = strlen($valueFiltered);
if ($length < 13 || $length > 19) {
$this->_error(self::LENGTH);
return false;
}
$sum = 0;
$weight = 2;
for ($i = $length - 2; $i >= 0; $i--) {
$digit = $weight * $valueFiltered[$i];
$sum += floor($digit / 10) + $digit % 10;
$weight = $weight % 2 + 1;
}
if ((10 - $sum % 10) % 10 != $valueFiltered[$length - 1]) {
$this->_error(self::CHECKSUM, $valueFiltered);
return false;
}
return true;
}
}

181
Zend/Validate/Date.php Normal file
View file

@ -0,0 +1,181 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Date.php 8553 2008-03-05 16:39:50Z darby $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Date extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value does not follow the YYYY-MM-DD format
*/
const NOT_YYYY_MM_DD = 'dateNotYYYY-MM-DD';
/**
* Validation failure message key for when the value does not appear to be a valid date
*/
const INVALID = 'dateInvalid';
/**
* Validation failure message key for when the value does not fit the given dateformat or locale
*/
const FALSEFORMAT = 'dateFalseFormat';
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::NOT_YYYY_MM_DD => "'%value%' is not of the format YYYY-MM-DD",
self::INVALID => "'%value%' does not appear to be a valid date",
self::FALSEFORMAT => "'%value%' does not fit given date format"
);
/**
* Optional format
*
* @var string|null
*/
protected $_format;
/**
* Optional locale
*
* @var string|Zend_Locale|null
*/
protected $_locale;
/**
* Sets validator options
*
* @param string $format OPTIONAL
* @param string|Zend_Locale $locale OPTIONAL
* @return void
*/
public function __construct($format = null, $locale = null)
{
$this->setFormat($format);
$this->setLocale($locale);
}
/**
* Returns the locale option
*
* @return string|Zend_Locale|null
*/
public function getLocale()
{
return $this->_locale;
}
/**
* Sets the locale option
*
* @param string|Zend_Locale $locale
* @return Zend_Validate_Date provides a fluent interface
*/
public function setLocale($locale = null)
{
if ($locale !== null) {
require_once 'Zend/Locale.php';
if (!Zend_Locale::isLocale($locale)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("The locale '$locale' is no known locale");
}
}
$this->_locale = $locale;
return $this;
}
/**
* Returns the locale option
*
* @return string|null
*/
public function getFormat()
{
return $this->_format;
}
/**
* Sets the format option
*
* @param string $format
* @return Zend_Validate_Date provides a fluent interface
*/
public function setFormat($format = null)
{
$this->_format = $format;
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if $value is a valid date of the format YYYY-MM-DD
* If optional $format or $locale is set the date format is checked
* according to Zend_Date, see Zend_Date::isDate()
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if (($this->_format !== null) or ($this->_locale !== null)) {
require_once 'Zend/Date.php';
if (!Zend_Date::isDate($value, $this->_format, $this->_locale)) {
$this->_error(self::FALSEFORMAT);
return false;
}
} else {
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $valueString)) {
$this->_error(self::NOT_YYYY_MM_DD);
return false;
}
list($year, $month, $day) = sscanf($valueString, '%d-%d-%d');
if (!checkdate($month, $day, $year)) {
$this->_error(self::INVALID);
return false;
}
}
return true;
}
}

100
Zend/Validate/Digits.php Normal file
View file

@ -0,0 +1,100 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Digits.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Digits extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value contains non-digit characters
*/
const NOT_DIGITS = 'notDigits';
/**
* Validation failure message key for when the value is an empty string
*/
const STRING_EMPTY = 'stringEmpty';
/**
* Digits filter used for validation
*
* @var Zend_Filter_Digits
*/
protected static $_filter = null;
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::NOT_DIGITS => "'%value%' contains not only digit characters",
self::STRING_EMPTY => "'%value%' is an empty string"
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value only contains digit characters
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if ('' === $valueString) {
$this->_error(self::STRING_EMPTY);
return false;
}
if (null === self::$_filter) {
/**
* @see Zend_Filter_Digits
*/
require_once 'Zend/Filter/Digits.php';
self::$_filter = new Zend_Filter_Digits();
}
if ($valueString !== self::$_filter->filter($valueString)) {
$this->_error(self::NOT_DIGITS);
return false;
}
return true;
}
}

View file

@ -0,0 +1,245 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: EmailAddress.php 8986 2008-03-21 21:38:32Z matthew $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @see Zend_Validate_Hostname
*/
require_once 'Zend/Validate/Hostname.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_EmailAddress extends Zend_Validate_Abstract
{
const INVALID = 'emailAddressInvalid';
const INVALID_HOSTNAME = 'emailAddressInvalidHostname';
const INVALID_MX_RECORD = 'emailAddressInvalidMxRecord';
const DOT_ATOM = 'emailAddressDotAtom';
const QUOTED_STRING = 'emailAddressQuotedString';
const INVALID_LOCAL_PART = 'emailAddressInvalidLocalPart';
/**
* @var array
*/
protected $_messageTemplates = array(
self::INVALID => "'%value%' is not a valid email address in the basic format local-part@hostname",
self::INVALID_HOSTNAME => "'%hostname%' is not a valid hostname for email address '%value%'",
self::INVALID_MX_RECORD => "'%hostname%' does not appear to have a valid MX record for the email address '%value%'",
self::DOT_ATOM => "'%localPart%' not matched against dot-atom format",
self::QUOTED_STRING => "'%localPart%' not matched against quoted-string format",
self::INVALID_LOCAL_PART => "'%localPart%' is not a valid local part for email address '%value%'"
);
/**
* @var array
*/
protected $_messageVariables = array(
'hostname' => '_hostname',
'localPart' => '_localPart'
);
/**
* Local object for validating the hostname part of an email address
*
* @var Zend_Validate_Hostname
*/
public $hostnameValidator;
/**
* Whether we check for a valid MX record via DNS
*
* @var boolean
*/
protected $_validateMx = false;
/**
* @var string
*/
protected $_hostname;
/**
* @var string
*/
protected $_localPart;
/**
* Instantiates hostname validator for local use
*
* You can pass a bitfield to determine what types of hostnames are allowed.
* These bitfields are defined by the ALLOW_* constants in Zend_Validate_Hostname
* The default is to allow DNS hostnames only
*
* @param integer $allow OPTIONAL
* @param bool $validateMx OPTIONAL
* @param Zend_Validate_Hostname $hostnameValidator OPTIONAL
* @return void
*/
public function __construct($allow = Zend_Validate_Hostname::ALLOW_DNS, $validateMx = false, Zend_Validate_Hostname $hostnameValidator = null)
{
$this->setValidateMx($validateMx);
$this->setHostnameValidator($hostnameValidator, $allow);
}
/**
* @param Zend_Validate_Hostname $hostnameValidator OPTIONAL
* @param int $allow OPTIONAL
* @return void
*/
public function setHostnameValidator(Zend_Validate_Hostname $hostnameValidator = null, $allow = Zend_Validate_Hostname::ALLOW_DNS)
{
if ($hostnameValidator === null) {
$hostnameValidator = new Zend_Validate_Hostname($allow);
}
$this->hostnameValidator = $hostnameValidator;
}
/**
* Whether MX checking via dns_get_mx is supported or not
*
* This currently only works on UNIX systems
*
* @return boolean
*/
public function validateMxSupported()
{
return function_exists('dns_get_mx');
}
/**
* Set whether we check for a valid MX record via DNS
*
* This only applies when DNS hostnames are validated
*
* @param boolean $allowed Set allowed to true to validate for MX records, and false to not validate them
*/
public function setValidateMx($allowed)
{
$this->_validateMx = (bool) $allowed;
}
/**
* 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;
}
}
}

View file

@ -0,0 +1,37 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Exception extends Zend_Exception
{}

75
Zend/Validate/Float.php Normal file
View file

@ -0,0 +1,75 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Float.php 8910 2008-03-19 20:19:23Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Float extends Zend_Validate_Abstract
{
const NOT_FLOAT = 'notFloat';
/**
* @var array
*/
protected $_messageTemplates = array(
self::NOT_FLOAT => "'%value%' does not appear to be a float"
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is a floating-point value
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
$locale = localeconv();
$valueFiltered = str_replace($locale['thousands_sep'], '', $valueString);
$valueFiltered = str_replace($locale['decimal_point'], '.', $valueFiltered);
if (strval(floatval($valueFiltered)) != $valueFiltered) {
$this->_error();
return false;
}
return true;
}
}

View file

@ -0,0 +1,114 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: GreaterThan.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_GreaterThan extends Zend_Validate_Abstract
{
const NOT_GREATER = 'notGreaterThan';
/**
* @var array
*/
protected $_messageTemplates = array(
self::NOT_GREATER => "'%value%' is not greater than '%min%'"
);
/**
* @var array
*/
protected $_messageVariables = array(
'min' => '_min'
);
/**
* Minimum value
*
* @var mixed
*/
protected $_min;
/**
* Sets validator options
*
* @param mixed $min
* @return void
*/
public function __construct($min)
{
$this->setMin($min);
}
/**
* Returns the min option
*
* @return mixed
*/
public function getMin()
{
return $this->_min;
}
/**
* Sets the min option
*
* @param mixed $min
* @return Zend_Validate_GreaterThan Provides a fluent interface
*/
public function setMin($min)
{
$this->_min = $min;
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is greater than min option
*
* @param mixed $value
* @return boolean
*/
public function isValid($value)
{
$this->_setValue($value);
if ($this->_min >= $value) {
$this->_error();
return false;
}
return true;
}
}

74
Zend/Validate/Hex.php Normal file
View file

@ -0,0 +1,74 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Hex.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Hex extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value contains characters other than hexadecimal digits
*/
const NOT_HEX = 'notHex';
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::NOT_HEX => "'%value%' has not only hexadecimal digit characters"
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value contains only hexadecimal digit characters
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if (!ctype_xdigit($valueString)) {
$this->_error();
return false;
}
return true;
}
}

444
Zend/Validate/Hostname.php Normal file
View file

@ -0,0 +1,444 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Hostname.php 8986 2008-03-21 21:38:32Z matthew $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* @see Zend_Validate_Ip
*/
require_once 'Zend/Validate/Ip.php';
/**
* Please note there are two standalone test scripts for testing IDN characters due to problems
* with file encoding.
*
* The first is tests/Zend/Validate/HostnameTestStandalone.php which is designed to be run on
* the command line.
*
* The second is tests/Zend/Validate/HostnameTestForm.php which is designed to be run via HTML
* to allow users to test entering UTF-8 characters in a form.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Hostname extends Zend_Validate_Abstract
{
const IP_ADDRESS_NOT_ALLOWED = 'hostnameIpAddressNotAllowed';
const UNKNOWN_TLD = 'hostnameUnknownTld';
const INVALID_DASH = 'hostnameDashCharacter';
const INVALID_HOSTNAME_SCHEMA = 'hostnameInvalidHostnameSchema';
const UNDECIPHERABLE_TLD = 'hostnameUndecipherableTld';
const INVALID_HOSTNAME = 'hostnameInvalidHostname';
const INVALID_LOCAL_NAME = 'hostnameInvalidLocalName';
const LOCAL_NAME_NOT_ALLOWED = 'hostnameLocalNameNotAllowed';
/**
* @var array
*/
protected $_messageTemplates = array(
self::IP_ADDRESS_NOT_ALLOWED => "'%value%' appears to be an IP address, but IP addresses are not allowed",
self::UNKNOWN_TLD => "'%value%' appears to be a DNS hostname but cannot match TLD against known list",
self::INVALID_DASH => "'%value%' appears to be a DNS hostname but contains a dash (-) in an invalid position",
self::INVALID_HOSTNAME_SCHEMA => "'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'",
self::UNDECIPHERABLE_TLD => "'%value%' appears to be a DNS hostname but cannot extract TLD part",
self::INVALID_HOSTNAME => "'%value%' does not match the expected structure for a DNS hostname",
self::INVALID_LOCAL_NAME => "'%value%' does not appear to be a valid local network name",
self::LOCAL_NAME_NOT_ALLOWED => "'%value%' appears to be a local network name but local network names are not allowed"
);
/**
* @var array
*/
protected $_messageVariables = array(
'tld' => '_tld'
);
/**
* Allows Internet domain names (e.g., example.com)
*/
const ALLOW_DNS = 1;
/**
* Allows IP addresses
*/
const ALLOW_IP = 2;
/**
* Allows local network names (e.g., localhost, www.localdomain)
*/
const ALLOW_LOCAL = 4;
/**
* Allows all types of hostnames
*/
const ALLOW_ALL = 7;
/**
* Whether IDN domains are validated
*
* @var boolean
*/
private $_validateIdn = true;
/**
* Whether TLDs are validated against a known list
*
* @var boolean
*/
private $_validateTld = true;
/**
* Bit field of ALLOW constants; determines which types of hostnames are allowed
*
* @var integer
*/
protected $_allow;
/**
* Bit field of CHECK constants; determines what additional hostname checks to make
*
* @var unknown_type
*/
// protected $_check;
/**
* Array of valid top-level-domains
*
* @var array
* @see ftp://data.iana.org/TLD/tlds-alpha-by-domain.txt List of all TLDs by domain
*/
protected $_validTlds = array(
'ac', 'ad', 'ae', 'aero', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao',
'aq', 'ar', 'arpa', 'as', 'asia', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb',
'bd', 'be', 'bf', 'bg', 'bh', 'bi', 'biz', 'bj', 'bm', 'bn', 'bo',
'br', 'bs', 'bt', 'bv', 'bw', 'by', 'bz', 'ca', 'cat', 'cc', 'cd',
'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'com', 'coop',
'cr', 'cu', 'cv', 'cx', 'cy', 'cz', 'de', 'dj', 'dk', 'dm', 'do',
'dz', 'ec', 'edu', 'ee', 'eg', 'er', 'es', 'et', 'eu', 'fi', 'fj',
'fk', 'fm', 'fo', 'fr', 'ga', 'gb', 'gd', 'ge', 'gf', 'gg', 'gh',
'gi', 'gl', 'gm', 'gn', 'gov', 'gp', 'gq', 'gr', 'gs', 'gt', 'gu',
'gw', 'gy', 'hk', 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il',
'im', 'in', 'info', 'int', 'io', 'iq', 'ir', 'is', 'it', 'je', 'jm',
'jo', 'jobs', 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kp', 'kr', 'kw',
'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'lr', 'ls', 'lt', 'lu',
'lv', 'ly', 'ma', 'mc', 'md', 'me', 'mg', 'mh', 'mil', 'mk', 'ml', 'mm',
'mn', 'mo', 'mobi', 'mp', 'mq', 'mr', 'ms', 'mt', 'mu', 'museum', 'mv',
'mw', 'mx', 'my', 'mz', 'na', 'name', 'nc', 'ne', 'net', 'nf', 'ng',
'ni', 'nl', 'no', 'np', 'nr', 'nu', 'nz', 'om', 'org', 'pa', 'pe',
'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'pro', 'ps', 'pt',
'pw', 'py', 'qa', 're', 'ro', 'rs', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd',
'se', 'sg', 'sh', 'si', 'sj', 'sk', 'sl', 'sm', 'sn', 'so', 'sr',
'st', 'su', 'sv', 'sy', 'sz', 'tc', 'td', 'tel', 'tf', 'tg', 'th', 'tj',
'tk', 'tl', 'tm', 'tn', 'to', 'tp', 'tr', 'travel', 'tt', 'tv', 'tw',
'tz', 'ua', 'ug', 'uk', 'um', 'us', 'uy', 'uz', 'va', 'vc', 've',
'vg', 'vi', 'vn', 'vu', 'wf', 'ws', 'ye', 'yt', 'yu', 'za', 'zm',
'zw'
);
/**
* @var string
*/
protected $_tld;
/**
* Sets validator options
*
* @param integer $allow OPTIONAL Set what types of hostname to allow (default ALLOW_DNS)
* @param boolean $validateIdn OPTIONAL Set whether IDN domains are validated (default true)
* @param boolean $validateTld OPTIONAL Set whether the TLD element of a hostname is validated (default true)
* @param Zend_Validate_Ip $ipValidator OPTIONAL
* @return void
* @see http://www.iana.org/cctld/specifications-policies-cctlds-01apr02.htm Technical Specifications for ccTLDs
*/
public function __construct($allow = self::ALLOW_DNS, $validateIdn = true, $validateTld = true, Zend_Validate_Ip $ipValidator = null)
{
// Set allow options
$this->setAllow($allow);
// Set validation options
$this->_validateIdn = $validateIdn;
$this->_validateTld = $validateTld;
$this->setIpValidator($ipValidator);
}
/**
* @param Zend_Validate_Ip $ipValidator OPTIONAL
* @return void;
*/
public function setIpValidator(Zend_Validate_Ip $ipValidator = null)
{
if ($ipValidator === null) {
$ipValidator = new Zend_Validate_Ip();
}
$this->_ipValidator = $ipValidator;
}
/**
* Returns the allow option
*
* @return integer
*/
public function getAllow()
{
return $this->_allow;
}
/**
* Sets the allow option
*
* @param integer $allow
* @return Zend_Validate_Hostname Provides a fluent interface
*/
public function setAllow($allow)
{
$this->_allow = $allow;
return $this;
}
/**
* Set whether IDN domains are validated
*
* This only applies when DNS hostnames are validated
*
* @param boolean $allowed Set allowed to true to validate IDNs, and false to not validate them
*/
public function setValidateIdn ($allowed)
{
$this->_validateIdn = (bool) $allowed;
}
/**
* Set whether the TLD element of a hostname is validated
*
* This only applies when DNS hostnames are validated
*
* @param boolean $allowed Set allowed to true to validate TLDs, and false to not validate them
*/
public function setValidateTld ($allowed)
{
$this->_validateTld = (bool) $allowed;
}
/**
* Sets the check option
*
* @param integer $check
* @return Zend_Validate_Hostname Provides a fluent interface
*/
/*
public function setCheck($check)
{
$this->_check = $check;
return $this;
}
*/
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the $value is a valid hostname with respect to the current allow option
*
* @param string $value
* @throws Zend_Validate_Exception if a fatal error occurs for validation process
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
// Check input against IP address schema
if ($this->_ipValidator->setTranslator($this->getTranslator())->isValid($valueString)) {
if (!($this->_allow & self::ALLOW_IP)) {
$this->_error(self::IP_ADDRESS_NOT_ALLOWED);
return false;
} else{
return true;
}
}
// Check input against DNS hostname schema
$domainParts = explode('.', $valueString);
if ((count($domainParts) > 1) && (strlen($valueString) >= 4) && (strlen($valueString) <= 254)) {
$status = false;
do {
// First check TLD
if (preg_match('/([a-z]{2,10})$/i', end($domainParts), $matches)) {
reset($domainParts);
// Hostname characters are: *(label dot)(label dot label); max 254 chars
// label: id-prefix [*ldh{61} id-prefix]; max 63 chars
// id-prefix: alpha / digit
// ldh: alpha / digit / dash
// Match TLD against known list
$this->_tld = strtolower($matches[1]);
if ($this->_validateTld) {
if (!in_array($this->_tld, $this->_validTlds)) {
$this->_error(self::UNKNOWN_TLD);
$status = false;
break;
}
}
/**
* Match against IDN hostnames
* @see Zend_Validate_Hostname_Interface
*/
$labelChars = 'a-z0-9';
$utf8 = false;
$classFile = 'Zend/Validate/Hostname/' . ucfirst($this->_tld) . '.php';
if ($this->_validateIdn) {
if (Zend_Loader::isReadable($classFile)) {
// Load additional characters
$className = 'Zend_Validate_Hostname_' . ucfirst($this->_tld);
Zend_Loader::loadClass($className);
$labelChars .= call_user_func(array($className, 'getCharacters'));
$utf8 = true;
}
}
// Keep label regex short to avoid issues with long patterns when matching IDN hostnames
$regexLabel = '/^[' . $labelChars . '\x2d]{1,63}$/i';
if ($utf8) {
$regexLabel .= 'u';
}
// Check each hostname part
$valid = true;
foreach ($domainParts as $domainPart) {
// Check dash (-) does not start, end or appear in 3rd and 4th positions
if (strpos($domainPart, '-') === 0 ||
(strlen($domainPart) > 2 && strpos($domainPart, '-', 2) == 2 && strpos($domainPart, '-', 3) == 3) ||
strrpos($domainPart, '-') === strlen($domainPart) - 1) {
$this->_error(self::INVALID_DASH);
$status = false;
break 2;
}
// Check each domain part
$status = @preg_match($regexLabel, $domainPart);
if ($status === false) {
/**
* Regex error
* @see Zend_Validate_Exception
*/
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Internal error: DNS validation failed');
} elseif ($status === 0) {
$valid = false;
}
}
// If all labels didn't match, the hostname is invalid
if (!$valid) {
$this->_error(self::INVALID_HOSTNAME_SCHEMA);
$status = false;
}
} else {
// Hostname not long enough
$this->_error(self::UNDECIPHERABLE_TLD);
$status = false;
}
} while (false);
// If the input passes as an Internet domain name, and domain names are allowed, then the hostname
// passes validation
if ($status && ($this->_allow & self::ALLOW_DNS)) {
return true;
}
} else {
$this->_error(self::INVALID_HOSTNAME);
}
// Check input against local network name schema; last chance to pass validation
$regexLocal = '/^(([a-zA-Z0-9\x2d]{1,63}\x2e)*[a-zA-Z0-9\x2d]{1,63}){1,254}$/';
$status = @preg_match($regexLocal, $valueString);
if (false === $status) {
/**
* Regex error
* @see Zend_Validate_Exception
*/
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Internal error: local network name validation failed');
}
// If the input passes as a local network name, and local network names are allowed, then the
// hostname passes validation
$allowLocal = $this->_allow & self::ALLOW_LOCAL;
if ($status && $allowLocal) {
return true;
}
// If the input does not pass as a local network name, add a message
if (!$status) {
$this->_error(self::INVALID_LOCAL_NAME);
}
// If local network names are not allowed, add a message
if (!$allowLocal) {
$this->_error(self::LOCAL_NAME_NOT_ALLOWED);
}
return false;
}
/**
* Throws an exception if a regex for $type does not exist
*
* @param string $type
* @throws Zend_Validate_Exception
* @return Zend_Validate_Hostname Provides a fluent interface
*/
/*
protected function _checkRegexType($type)
{
if (!isset($this->_regex[$type])) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("'$type' must be one of ('" . implode(', ', array_keys($this->_regex))
. "')");
}
return $this;
}
*/
}

View file

@ -0,0 +1,50 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: At.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Hostname_Interface
*/
require_once 'Zend/Validate/Hostname/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Hostname_At implements Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* @see http://www.nic.at/en/service/technical_information/idn/charset_converter/ Austria (.AT)
* @return string
*/
static function getCharacters()
{
return '\x{00EO}-\x{00F6}\x{00F8}-\x{00FF}\x{0153}\x{0161}\x{017E}';
}
}

View file

@ -0,0 +1,50 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Ch.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Hostname_Interface
*/
require_once 'Zend/Validate/Hostname/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Hostname_Ch implements Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* @see https://nic.switch.ch/reg/ocView.action?res=EF6GW2JBPVTG67DLNIQXU234MN6SC33JNQQGI7L6#anhang1 Switzerland (.CH)
* @return string
*/
static function getCharacters()
{
return '\x{00EO}-\x{00F6}\x{00F8}-\x{00FF}\x{0153}';
}
}

View file

@ -0,0 +1,58 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: De.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Hostname_Interface
*/
require_once 'Zend/Validate/Hostname/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Hostname_De implements Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* @see http://www.denic.de/en/domains/idns/liste.html Germany (.DE) alllowed characters
* @return string
*/
static function getCharacters()
{
return '\x{00E1}\x{00E0}\x{0103}\x{00E2}\x{00E5}\x{00E4}\x{00E3}\x{0105}\x{0101}\x{00E6}\x{0107}' .
'\x{0109}\x{010D}\x{010B}\x{00E7}\x{010F}\x{0111}\x{00E9}\x{00E8}\x{0115}\x{00EA}\x{011B}' .
'\x{00EB}\x{0117}\x{0119}\x{0113}\x{011F}\x{011D}\x{0121}\x{0123}\x{0125}\x{0127}\x{00ED}' .
'\x{00EC}\x{012D}\x{00EE}\x{00EF}\x{0129}\x{012F}\x{012B}\x{0131}\x{0135}\x{0137}\x{013A}' .
'\x{013E}\x{013C}\x{0142}\x{0144}\x{0148}\x{00F1}\x{0146}\x{014B}\x{00F3}\x{00F2}\x{014F}' .
'\x{00F4}\x{00F6}\x{0151}\x{00F5}\x{00F8}\x{014D}\x{0153}\x{0138}\x{0155}\x{0159}\x{0157}' .
'\x{015B}\x{015D}\x{0161}\x{015F}\x{0165}\x{0163}\x{0167}\x{00FA}\x{00F9}\x{016D}\x{00FB}' .
'\x{016F}\x{00FC}\x{0171}\x{0169}\x{0173}\x{016B}\x{0175}\x{00FD}\x{0177}\x{00FF}\x{017A}' .
'\x{017E}\x{017C}\x{00F0}\x{00FE}';
}
}

View file

@ -0,0 +1,50 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Fi.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Hostname_Interface
*/
require_once 'Zend/Validate/Hostname/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Hostname_Fi implements Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* @see http://www.ficora.fi/en/index/palvelut/fiverkkotunnukset/aakkostenkaytto.html Finland (.FI)
* @return string
*/
static function getCharacters()
{
return '\x{00E5}\x{00E4}\x{00F6}';
}
}

View file

@ -0,0 +1,50 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Hu.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Hostname_Interface
*/
require_once 'Zend/Validate/Hostname/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Hostname_Hu implements Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* @see http://www.domain.hu/domain/English/szabalyzat.html Hungary (.HU)
* @return string
*/
static function getCharacters()
{
return '\x{00E1}\x{00E9}\x{00ED}\x{00F3}\x{00F6}\x{0151}\x{00FA}\x{00FC}\x{0171}';
}
}

View file

@ -0,0 +1,52 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Interface.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* UTF-8 characters should be written as four character hex codes \x{XXXX}
* For example é (lowercase e with acute) is represented by the hex code \x{00E9}
*
* You only need to include lower-case equivalents of characters since the hostname
* check is case-insensitive
*
* Please document the supported TLDs in the documentation file at:
* manual/en/module_specs/Zend_Validate-Hostname.xml
*
* @see http://en.wikipedia.org/wiki/Internationalized_domain_name
* @see http://www.iana.org/cctld/ Country-Code Top-Level Domains (TLDs)
* @see http://www.columbia.edu/kermit/utf8-t1.html UTF-8 characters
* @return string
*/
static function getCharacters();
}

View file

@ -0,0 +1,50 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Li.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Hostname_Interface
*/
require_once 'Zend/Validate/Hostname/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Hostname_Li implements Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* @see https://nic.switch.ch/reg/ocView.action?res=EF6GW2JBPVTG67DLNIQXU234MN6SC33JNQQGI7L6#anhang1 Liechtenstein (.LI)
* @return string
*/
static function getCharacters()
{
return '\x{00EO}-\x{00F6}\x{00F8}-\x{00FF}\x{0153}';
}
}

View file

@ -0,0 +1,52 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: No.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Hostname_Interface
*/
require_once 'Zend/Validate/Hostname/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Hostname_No implements Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* @see http://www.norid.no/domeneregistrering/idn/idn_nyetegn.en.html Norway (.NO)
* @return string
*/
static function getCharacters()
{
return '\x00E1\x00E0\x00E4\x010D\x00E7\x0111\x00E9\x00E8\x00EA\x\x014B' .
'\x0144\x00F1\x00F3\x00F2\x00F4\x00F6\x0161\x0167\x00FC\x017E\x00E6' .
'\x00F8\x00E5';
}
}

View file

@ -0,0 +1,50 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Se.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Hostname_Interface
*/
require_once 'Zend/Validate/Hostname/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Hostname_Se implements Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* @see http://www.iis.se/english/IDN_campaignsite.shtml?lang=en Sweden (.SE)
* @return string
*/
static function getCharacters()
{
return '\x{00E5}\x{00E4}\x{00F6}\x{00FC}\x{00E9}';
}
}

117
Zend/Validate/Identical.php Normal file
View file

@ -0,0 +1,117 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Identical.php 8118 2008-02-18 16:10:32Z matthew $
*/
/** Zend_Validate_Abstract */
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Identical extends Zend_Validate_Abstract
{
/**#@+
* Error codes
* @const string
*/
const NOT_SAME = 'notSame';
const MISSING_TOKEN = 'missingToken';
/**#@-*/
/**
* Error messages
* @var array
*/
protected $_messageTemplates = array(
self::NOT_SAME => 'Tokens do not match',
self::MISSING_TOKEN => 'No token was provided to match against',
);
/**
* Original token against which to validate
* @var string
*/
protected $_token;
/**
* Sets validator options
*
* @param string $token
* @return void
*/
public function __construct($token = null)
{
if (null !== $token) {
$this->setToken($token);
}
}
/**
* Set token against which to compare
*
* @param string $token
* @return Zend_Validate_Identical
*/
public function setToken($token)
{
$this->_token = (string) $token;
return $this;
}
/**
* Retrieve token
*
* @return string
*/
public function getToken()
{
return $this->_token;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if a token has been set and the provided value
* matches that token.
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$this->_setValue($value);
$token = $this->getToken();
if (empty($token)) {
$this->_error(self::MISSING_TOKEN);
return false;
}
if ($value !== $token) {
$this->_error(self::NOT_SAME);
return false;
}
return true;
}
}

138
Zend/Validate/InArray.php Normal file
View file

@ -0,0 +1,138 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: InArray.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_InArray extends Zend_Validate_Abstract
{
const NOT_IN_ARRAY = 'notInArray';
/**
* @var array
*/
protected $_messageTemplates = array(
self::NOT_IN_ARRAY => "'%value%' was not found in the haystack"
);
/**
* Haystack of possible values
*
* @var array
*/
protected $_haystack;
/**
* Whether a strict in_array() invocation is used
*
* @var boolean
*/
protected $_strict;
/**
* Sets validator options
*
* @param array $haystack
* @param boolean $strict
* @return void
*/
public function __construct(array $haystack, $strict = false)
{
$this->setHaystack($haystack)
->setStrict($strict);
}
/**
* Returns the haystack option
*
* @return mixed
*/
public function getHaystack()
{
return $this->_haystack;
}
/**
* Sets the haystack option
*
* @param mixed $haystack
* @return Zend_Validate_InArray Provides a fluent interface
*/
public function setHaystack(array $haystack)
{
$this->_haystack = $haystack;
return $this;
}
/**
* Returns the strict option
*
* @return boolean
*/
public function getStrict()
{
return $this->_strict;
}
/**
* Sets the strict option
*
* @param boolean $strict
* @return Zend_Validate_InArray Provides a fluent interface
*/
public function setStrict($strict)
{
$this->_strict = $strict;
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is contained in the haystack option. If the strict
* option is true, then the type of $value is also checked.
*
* @param mixed $value
* @return boolean
*/
public function isValid($value)
{
$this->_setValue($value);
if (!in_array($value, $this->_haystack, $this->_strict)) {
$this->_error();
return false;
}
return true;
}
}

75
Zend/Validate/Int.php Normal file
View file

@ -0,0 +1,75 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Int.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Int extends Zend_Validate_Abstract
{
const NOT_INT = 'notInt';
/**
* @var array
*/
protected $_messageTemplates = array(
self::NOT_INT => "'%value%' does not appear to be an integer"
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is a valid integer
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
$locale = localeconv();
$valueFiltered = str_replace($locale['decimal_point'], '.', $valueString);
$valueFiltered = str_replace($locale['thousands_sep'], '', $valueFiltered);
if (strval(intval($valueFiltered)) != $valueFiltered) {
$this->_error();
return false;
}
return true;
}
}

View file

@ -0,0 +1,71 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Interface.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Validate_Interface
{
/**
* 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);
/**
* Returns an array of messages that explain why the most recent isValid()
* call returned false. The array keys are validation failure message identifiers,
* and the array values are the corresponding human-readable message strings.
*
* If isValid() was never called or if the most recent isValid() call
* returned true, then this method returns an empty array.
*
* @return array
*/
public function getMessages();
/**
* Returns an array of message codes that explain why a previous isValid() call
* returned false.
*
* If isValid() was never called or if the most recent isValid() call
* returned true, then this method returns an empty array.
*
* This is now the same as calling array_keys() on the return value from getMessages().
*
* @return array
* @deprecated Since 1.5.0
*/
public function getErrors();
}

70
Zend/Validate/Ip.php Normal file
View file

@ -0,0 +1,70 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Ip.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Ip extends Zend_Validate_Abstract
{
const NOT_IP_ADDRESS = 'notIpAddress';
/**
* @var array
*/
protected $_messageTemplates = array(
self::NOT_IP_ADDRESS => "'%value%' does not appear to be a valid IP address"
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is a valid IP address
*
* @param mixed $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if (ip2long($valueString) === false) {
$this->_error();
return false;
}
return true;
}
}

113
Zend/Validate/LessThan.php Normal file
View file

@ -0,0 +1,113 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: LessThan.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_LessThan extends Zend_Validate_Abstract
{
const NOT_LESS = 'notLessThan';
/**
* @var array
*/
protected $_messageTemplates = array(
self::NOT_LESS => "'%value%' is not less than '%max%'"
);
/**
* @var array
*/
protected $_messageVariables = array(
'max' => '_max'
);
/**
* Maximum value
*
* @var mixed
*/
protected $_max;
/**
* Sets validator options
*
* @param mixed $max
* @return void
*/
public function __construct($max)
{
$this->setMax($max);
}
/**
* Returns the max option
*
* @return mixed
*/
public function getMax()
{
return $this->_max;
}
/**
* Sets the max option
*
* @param mixed $max
* @return Zend_Validate_LessThan Provides a fluent interface
*/
public function setMax($max)
{
$this->_max = $max;
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is less than max option
*
* @param mixed $value
* @return boolean
*/
public function isValid($value)
{
$this->_setValue($value);
if ($this->_max <= $value) {
$this->_error();
return false;
}
return true;
}
}

View file

@ -0,0 +1,70 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: NotEmpty.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_NotEmpty extends Zend_Validate_Abstract
{
const IS_EMPTY = 'isEmpty';
/**
* @var array
*/
protected $_messageTemplates = array(
self::IS_EMPTY => "Value is empty, but a non-empty value is required"
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is not an empty value.
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if (empty($value)) {
$this->_error();
return false;
}
return true;
}
}

125
Zend/Validate/Regex.php Normal file
View file

@ -0,0 +1,125 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Regex.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_Regex extends Zend_Validate_Abstract
{
const NOT_MATCH = 'regexNotMatch';
/**
* @var array
*/
protected $_messageTemplates = array(
self::NOT_MATCH => "'%value%' does not match against pattern '%pattern%'"
);
/**
* @var array
*/
protected $_messageVariables = array(
'pattern' => '_pattern'
);
/**
* Regular expression pattern
*
* @var string
*/
protected $_pattern;
/**
* Sets validator options
*
* @param string $pattern
* @return void
*/
public function __construct($pattern)
{
$this->setPattern($pattern);
}
/**
* Returns the pattern option
*
* @return string
*/
public function getPattern()
{
return $this->_pattern;
}
/**
* Sets the pattern option
*
* @param string $pattern
* @return Zend_Validate_Regex Provides a fluent interface
*/
public function setPattern($pattern)
{
$this->_pattern = (string) $pattern;
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value matches against the pattern option
*
* @param string $value
* @throws Zend_Validate_Exception if there is a fatal error in pattern matching
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
$status = @preg_match($this->_pattern, $valueString);
if (false === $status) {
/**
* @see Zend_Validate_Exception
*/
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("Internal error matching pattern '$this->_pattern' against value '$valueString'");
}
if (!$status) {
$this->_error();
return false;
}
return true;
}
}

View file

@ -0,0 +1,180 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: StringLength.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_StringLength extends Zend_Validate_Abstract
{
const TOO_SHORT = 'stringLengthTooShort';
const TOO_LONG = 'stringLengthTooLong';
/**
* @var array
*/
protected $_messageTemplates = array(
self::TOO_SHORT => "'%value%' is less than %min% characters long",
self::TOO_LONG => "'%value%' is greater than %max% characters long"
);
/**
* @var array
*/
protected $_messageVariables = array(
'min' => '_min',
'max' => '_max'
);
/**
* Minimum length
*
* @var integer
*/
protected $_min;
/**
* Maximum length
*
* If null, there is no maximum length
*
* @var integer|null
*/
protected $_max;
/**
* Sets validator options
*
* @param integer $min
* @param integer $max
* @return void
*/
public function __construct($min = 0, $max = null)
{
$this->setMin($min);
$this->setMax($max);
}
/**
* Returns the min option
*
* @return integer
*/
public function getMin()
{
return $this->_min;
}
/**
* Sets the min option
*
* @param integer $min
* @throws Zend_Validate_Exception
* @return Zend_Validate_StringLength Provides a fluent interface
*/
public function setMin($min)
{
if (null !== $this->_max && $min > $this->_max) {
/**
* @see Zend_Validate_Exception
*/
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("The minimum must be less than or equal to the maximum length, but $min >"
. " $this->_max");
}
$this->_min = max(0, (integer) $min);
return $this;
}
/**
* Returns the max option
*
* @return integer|null
*/
public function getMax()
{
return $this->_max;
}
/**
* Sets the max option
*
* @param integer|null $max
* @throws Zend_Validate_Exception
* @return Zend_Validate_StringLength Provides a fluent interface
*/
public function setMax($max)
{
if (null === $max) {
$this->_max = null;
} else if ($max < $this->_min) {
/**
* @see Zend_Validate_Exception
*/
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("The maximum must be greater than or equal to the minimum length, but "
. "$max < $this->_min");
} else {
$this->_max = (integer) $max;
}
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the string length of $value is at least the min option and
* no greater than the max option (when the max option is not null).
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
$length = iconv_strlen($valueString);
if ($length < $this->_min) {
$this->_error(self::TOO_SHORT);
}
if (null !== $this->_max && $this->_max < $length) {
$this->_error(self::TOO_LONG);
}
if (count($this->_messages)) {
return false;
} else {
return true;
}
}
}