diff options
author | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-06-23 07:02:26 +0400 |
---|---|---|
committer | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-06-23 07:02:26 +0400 |
commit | 999f46479294713104c962bfe7469e9b6e7a4bbf (patch) | |
tree | a22e349d850bc2f2946a85a3cab373c4b6dc1809 /libs/Zend/Validate | |
parent | 462d78c290f19dd691d9634bf2b17d2adc4446af (diff) | |
parent | c0b42ff664a0846064df23db232ea774931ab7a3 (diff) |
0.6.3?
Diffstat (limited to 'libs/Zend/Validate')
87 files changed, 1069 insertions, 5365 deletions
diff --git a/libs/Zend/Validate/Abstract.php b/libs/Zend/Validate/Abstract.php index cbecc5eebf..3107360619 100644 --- a/libs/Zend/Validate/Abstract.php +++ b/libs/Zend/Validate/Abstract.php @@ -14,20 +14,20 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Abstract.php 21726 2010-03-31 19:57:27Z rob $ + * @version $Id: Abstract.php 18688 2009-10-25 16:08:24Z thomas $ */ /** * @see Zend_Validate_Interface */ -// require_once 'Zend/Validate/Interface.php'; +require_once 'Zend/Validate/Interface.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 @@ -149,7 +149,7 @@ abstract class Zend_Validate_Abstract implements Zend_Validate_Interface } if (!isset($this->_messageTemplates[$messageKey])) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("No message template exists for key '$messageKey'"); } @@ -191,7 +191,7 @@ abstract class Zend_Validate_Abstract implements Zend_Validate_Interface /** * @see Zend_Validate_Exception */ - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("No property exists by the name '$property'"); } @@ -251,11 +251,11 @@ abstract class Zend_Validate_Abstract implements Zend_Validate_Interface } /** - * @param string $messageKey + * @param string $messageKey OPTIONAL * @param string $value OPTIONAL * @return void */ - protected function _error($messageKey, $value = null) + protected function _error($messageKey = null, $value = null) { if ($messageKey === null) { $keys = array_keys($this->_messageTemplates); @@ -328,7 +328,7 @@ abstract class Zend_Validate_Abstract implements Zend_Validate_Interface } elseif ($translator instanceof Zend_Translate) { $this->_translator = $translator->getAdapter(); } else { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception('Invalid translator specified'); } return $this; @@ -353,16 +353,6 @@ abstract class Zend_Validate_Abstract implements Zend_Validate_Interface } /** - * Does this validator have its own specific translator? - * - * @return bool - */ - public function hasTranslator() - { - return (bool)$this->_translator; - } - - /** * Set default translation object for all validate objects * * @param Zend_Translate|Zend_Translate_Adapter|null $translator @@ -375,7 +365,7 @@ abstract class Zend_Validate_Abstract implements Zend_Validate_Interface } elseif ($translator instanceof Zend_Translate) { self::$_defaultTranslator = $translator->getAdapter(); } else { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception('Invalid translator specified'); } } @@ -388,7 +378,7 @@ abstract class Zend_Validate_Abstract implements Zend_Validate_Interface public static function getDefaultTranslator() { if (null === self::$_defaultTranslator) { - // require_once 'Zend/Registry.php'; + require_once 'Zend/Registry.php'; if (Zend_Registry::isRegistered('Zend_Translate')) { $translator = Zend_Registry::get('Zend_Translate'); if ($translator instanceof Zend_Translate_Adapter) { @@ -403,16 +393,6 @@ abstract class Zend_Validate_Abstract implements Zend_Validate_Interface } /** - * Is there a default translation object set? - * - * @return boolean - */ - public static function hasDefaultTranslator() - { - return (bool)self::$_defaultTranslator; - } - - /** * Indicate whether or not translation should be disabled * * @param bool $flag diff --git a/libs/Zend/Validate/Alnum.php b/libs/Zend/Validate/Alnum.php index 9db12a3062..c2f2f46642 100644 --- a/libs/Zend/Validate/Alnum.php +++ b/libs/Zend/Validate/Alnum.php @@ -14,33 +14,33 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Alnum.php 20442 2010-01-20 15:15:40Z matthew $ + * @version $Id: Alnum.php 17467 2009-08-08 18:06:55Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 { const INVALID = 'alnumInvalid'; const NOT_ALNUM = 'notAlnum'; - const STRING_EMPTY = 'alnumStringEmpty'; + const STRING_EMPTY = 'stringEmpty'; /** * Whether to allow white space characters; off by default * * @var boolean - * @deprecated + * @depreciated */ public $allowWhiteSpace; @@ -58,30 +58,18 @@ class Zend_Validate_Alnum extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be float, string, or integer", - self::NOT_ALNUM => "'%value%' contains characters which are non alphabetic and no digits", - self::STRING_EMPTY => "'%value%' is an empty string", + 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|Zend_Config $allowWhiteSpace + * @param boolean $allowWhiteSpace * @return void */ public function __construct($allowWhiteSpace = false) { - if ($allowWhiteSpace instanceof Zend_Config) { - $allowWhiteSpace = $allowWhiteSpace->toArray(); - } - - if (is_array($allowWhiteSpace)) { - if (array_key_exists('allowWhiteSpace', $allowWhiteSpace)) { - $allowWhiteSpace = $allowWhiteSpace['allowWhiteSpace']; - } else { - $allowWhiteSpace = false; - } - } - $this->allowWhiteSpace = (boolean) $allowWhiteSpace; } @@ -133,7 +121,7 @@ class Zend_Validate_Alnum extends Zend_Validate_Abstract /** * @see Zend_Filter_Alnum */ - // require_once 'Zend/Filter/Alnum.php'; + require_once 'Zend/Filter/Alnum.php'; self::$_filter = new Zend_Filter_Alnum(); } diff --git a/libs/Zend/Validate/Alpha.php b/libs/Zend/Validate/Alpha.php index 42864fa561..ce1f01872f 100644 --- a/libs/Zend/Validate/Alpha.php +++ b/libs/Zend/Validate/Alpha.php @@ -14,33 +14,33 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Alpha.php 20442 2010-01-20 15:15:40Z matthew $ + * @version $Id: Alpha.php 16223 2009-06-21 20:04:53Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 { const INVALID = 'alphaInvalid'; const NOT_ALPHA = 'notAlpha'; - const STRING_EMPTY = 'alphaStringEmpty'; + const STRING_EMPTY = 'stringEmpty'; /** * Whether to allow white space characters; off by default * * @var boolean - * @deprecated + * @depreciated */ public $allowWhiteSpace; @@ -58,30 +58,18 @@ class Zend_Validate_Alpha extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be a string", - self::NOT_ALPHA => "'%value%' contains non alphabetic characters", + 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|Zend_Config $allowWhiteSpace + * @param boolean $allowWhiteSpace * @return void */ public function __construct($allowWhiteSpace = false) { - if ($allowWhiteSpace instanceof Zend_Config) { - $allowWhiteSpace = $allowWhiteSpace->toArray(); - } - - if (is_array($allowWhiteSpace)) { - if (array_key_exists('allowWhiteSpace', $allowWhiteSpace)) { - $allowWhiteSpace = $allowWhiteSpace['allowWhiteSpace']; - } else { - $allowWhiteSpace = false; - } - } - $this->allowWhiteSpace = (boolean) $allowWhiteSpace; } @@ -133,7 +121,7 @@ class Zend_Validate_Alpha extends Zend_Validate_Abstract /** * @see Zend_Filter_Alpha */ - // require_once 'Zend/Filter/Alpha.php'; + require_once 'Zend/Filter/Alpha.php'; self::$_filter = new Zend_Filter_Alpha(); } diff --git a/libs/Zend/Validate/Barcode.php b/libs/Zend/Validate/Barcode.php index 111010880e..374a9e5449 100644 --- a/libs/Zend/Validate/Barcode.php +++ b/libs/Zend/Validate/Barcode.php @@ -14,164 +14,70 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Barcode.php 21748 2010-04-03 10:29:56Z thomas $ + * @version $Id: Barcode.php 16223 2009-06-21 20:04:53Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; - -/** - * @see Zend_Loader - */ -// require_once 'Zend/Loader.php'; +require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 { - const INVALID = 'barcodeInvalid'; - const FAILED = 'barcodeFailed'; - const INVALID_CHARS = 'barcodeInvalidChars'; - const INVALID_LENGTH = 'barcodeInvalidLength'; - - protected $_messageTemplates = array( - self::FAILED => "'%value%' failed checksum validation", - self::INVALID_CHARS => "'%value%' contains invalid characters", - self::INVALID_LENGTH => "'%value%' should have a length of %length% characters", - self::INVALID => "Invalid type given, value should be string", - ); - - /** - * Additional variables available for validation failure messages - * - * @var array - */ - protected $_messageVariables = array( - 'length' => '_length' - ); - - /** - * Length for the set subtype - * - * @var integer - */ - protected $_length; - /** - * Barcode adapter + * Barcode validator * - * @var Zend_Validate_Barcode_BarcodeAdapter + * @var Zend_Validate_Abstract */ - protected $_adapter; + protected $_barcodeValidator; /** * Generates the standard validator object * - * @param string|Zend_Config| - * Zend_Validate_Barcode_BarcodeAdapter $adapter Barcode adapter to use + * @param string $barcodeType - Barcode validator to use * @return void * @throws Zend_Validate_Exception */ - public function __construct($adapter) - { - if ($adapter instanceof Zend_Config) { - $adapter = $adapter->toArray(); - } - - $options = null; - $checksum = null; - if (is_array($adapter)) { - if (array_key_exists('options', $adapter)) { - $options = $adapter['options']; - } - - if (array_key_exists('checksum', $adapter)) { - $checksum = $adapter['checksum']; - } - - if (array_key_exists('adapter', $adapter)) { - $adapter = $adapter['adapter']; - } else { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception("Missing option 'adapter'"); - } - } - - $this->setAdapter($adapter, $options); - if ($checksum !== null) { - $this->setChecksum($checksum); - } - } - - /** - * Returns the set adapter - * - * @return Zend_Validate_Barcode_BarcodeAdapter - */ - public function getAdapter() + public function __construct($barcodeType) { - return $this->_adapter; + $this->setType($barcodeType); } /** - * Sets a new barcode adapter + * Sets a new barcode validator * - * @param string|Zend_Validate_Barcode $adapter Barcode adapter to use - * @param array $options Options for this adapter + * @param string $barcodeType - Barcode validator to use * @return void * @throws Zend_Validate_Exception */ - public function setAdapter($adapter, $options = null) + public function setType($barcodeType) { - $adapter = ucfirst(strtolower($adapter)); - // require_once 'Zend/Loader.php'; - if (Zend_Loader::isReadable('Zend/Validate/Barcode/' . $adapter. '.php')) { - $adapter = 'Zend_Validate_Barcode_' . $adapter; - } - - // if (!class_exists($adapter)) { - // Zend_Loader::loadClass($adapter); - // } - - $this->_adapter = new $adapter($options); - if (!$this->_adapter instanceof Zend_Validate_Barcode_AdapterInterface) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception( - "Adapter " . $adapter . " does not implement Zend_Validate_Barcode_AdapterInterface" - ); + switch (strtolower($barcodeType)) { + case 'upc': + case 'upc-a': + require_once 'Zend/Validate/Barcode/UpcA.php'; + $class = 'Zend_Validate_Barcode_UpcA'; + break; + case 'ean13': + case 'ean-13': + require_once 'Zend/Validate/Barcode/Ean13.php'; + $class = 'Zend_Validate_Barcode_Ean13'; + break; + default: + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception("Barcode type '$barcodeType' is not supported'"); + break; } - return $this; - } - - /** - * Returns the checksum option - * - * @return boolean - */ - public function getChecksum() - { - return $this->getAdapter()->getCheck(); - } - - /** - * Sets the checksum option - * - * @param boolean $checksum - * @return Zend_Validate_Barcode - */ - public function setChecksum($checksum) - { - $this->getAdapter()->setCheck($checksum); - return $this; + $this->_barcodeValidator = new $class; } /** @@ -184,34 +90,6 @@ class Zend_Validate_Barcode extends Zend_Validate_Abstract */ public function isValid($value) { - if (!is_string($value)) { - $this->_error(self::INVALID); - return false; - } - - $this->_setValue($value); - $adapter = $this->getAdapter(); - $this->_length = $adapter->getLength(); - $result = $adapter->checkLength($value); - if (!$result) { - $this->_error(self::INVALID_LENGTH); - return false; - } - - $result = $adapter->checkChars($value); - if (!$result) { - $this->_error(self::INVALID_CHARS); - return false; - } - - if ($this->getChecksum()) { - $result = $adapter->checksum($value); - if (!$result) { - $this->_error(self::FAILED); - return false; - } - } - - return true; + return call_user_func(array($this->_barcodeValidator, 'isValid'), $value); } } diff --git a/libs/Zend/Validate/Barcode/AdapterAbstract.php b/libs/Zend/Validate/Barcode/AdapterAbstract.php deleted file mode 100644 index 7cbb4644f8..0000000000 --- a/libs/Zend/Validate/Barcode/AdapterAbstract.php +++ /dev/null @@ -1,315 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ - */ - -/** - * @see Zend_Validate_Barcode_AdapterInterface - */ -// require_once 'Zend/Validate/Barcode/AdapterInterface.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -abstract class Zend_Validate_Barcode_AdapterAbstract - implements Zend_Validate_Barcode_AdapterInterface -{ - /** - * Allowed barcode lengths - * @var integer|array|string - */ - protected $_length; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters; - - /** - * Callback to checksum function - * @var string|array - */ - protected $_checksum; - - /** - * Is a checksum value included? - * @var boolean - */ - protected $_hasChecksum = true; - - /** - * Checks the length of a barcode - * - * @param string $value The barcode to check for proper length - * @return boolean - */ - public function checkLength($value) - { - if (!is_string($value)) { - return false; - } - - $fixum = strlen($value); - $found = false; - $length = $this->getLength(); - if (is_array($length)) { - foreach ($length as $value) { - if ($fixum == $value) { - $found = true; - } - - if ($value == -1) { - $found = true; - } - } - } elseif ($fixum == $length) { - $found = true; - } elseif ($length == -1) { - $found = true; - } elseif ($length == 'even') { - $count = $fixum % 2; - $found = ($count == 0) ? true : false; - } elseif ($length == 'odd') { - $count = $fixum % 2; - $found = ($count == 1) ? true : false; - } - - return $found; - } - - /** - * Checks for allowed characters within the barcode - * - * @param string $value The barcode to check for allowed characters - * @return boolean - */ - public function checkChars($value) - { - if (!is_string($value)) { - return false; - } - - $characters = $this->getCharacters(); - if ($characters == 128) { - for ($x = 0; $x < 128; ++$x) { - $value = str_replace(chr($x), '', $value); - } - } else { - $chars = str_split($characters); - foreach ($chars as $char) { - $value = str_replace($char, '', $value); - } - } - - if (strlen($value) > 0) { - return false; - } - - return true; - } - - /** - * Validates the checksum - * - * @param string $value The barcode to check the checksum for - * @return boolean - */ - public function checksum($value) - { - $checksum = $this->getChecksum(); - if (!empty($checksum)) { - if (method_exists($this, $checksum)) { - return call_user_func(array($this, $checksum), $value); - } - } - - return false; - } - - /** - * Returns the allowed barcode length - * - * @return string - */ - public function getLength() - { - return $this->_length; - } - - /** - * Returns the allowed characters - * - * @return integer|string - */ - public function getCharacters() - { - return $this->_characters; - } - - /** - * Returns the checksum function name - * - */ - public function getChecksum() - { - return $this->_checksum; - } - - /** - * Returns if barcode uses checksum - * - * @return boolean - */ - public function getCheck() - { - return $this->_hasChecksum; - } - - /** - * Sets the checksum validation - * - * @param boolean $check - * @return Zend_Validate_Barcode_AdapterAbstract - */ - public function setCheck($check) - { - $this->_hasChecksum = (boolean) $check; - return $this; - } - - /** - * Validates the checksum (Modulo 10) - * GTIN implementation factor 3 - * - * @param string $value The barcode to validate - * @return boolean - */ - protected function _gtin($value) - { - $barcode = substr($value, 0, -1); - $sum = 0; - $length = strlen($barcode) - 1; - - for ($i = 0; $i <= $length; $i++) { - if (($i % 2) === 0) { - $sum += $barcode[$length - $i] * 3; - } else { - $sum += $barcode[$length - $i]; - } - } - - $calc = $sum % 10; - $checksum = ($calc === 0) ? 0 : (10 - $calc); - if ($value[$length + 1] != $checksum) { - return false; - } - - return true; - } - - /** - * Validates the checksum (Modulo 10) - * IDENTCODE implementation factors 9 and 4 - * - * @param string $value The barcode to validate - * @return boolean - */ - protected function _identcode($value) - { - $barcode = substr($value, 0, -1); - $sum = 0; - $length = strlen($value) - 2; - - for ($i = 0; $i <= $length; $i++) { - if (($i % 2) === 0) { - $sum += $barcode[$length - $i] * 4; - } else { - $sum += $barcode[$length - $i] * 9; - } - } - - $calc = $sum % 10; - $checksum = ($calc === 0) ? 0 : (10 - $calc); - if ($value[$length + 1] != $checksum) { - return false; - } - - return true; - } - - /** - * Validates the checksum (Modulo 10) - * CODE25 implementation factor 3 - * - * @param string $value The barcode to validate - * @return boolean - */ - protected function _code25($value) - { - $barcode = substr($value, 0, -1); - $sum = 0; - $length = strlen($barcode) - 1; - - for ($i = 0; $i <= $length; $i++) { - if (($i % 2) === 0) { - $sum += $barcode[$i] * 3; - } else { - $sum += $barcode[$i]; - } - } - - $calc = $sum % 10; - $checksum = ($calc === 0) ? 0 : (10 - $calc); - if ($value[$length + 1] != $checksum) { - return false; - } - - return true; - } - - /** - * Validates the checksum () - * POSTNET implementation - * - * @param string $value The barcode to validate - * @return boolean - */ - protected function _postnet($value) - { - $checksum = substr($value, -1, 1); - $values = str_split(substr($value, 0, -1)); - - $check = 0; - foreach($values as $row) { - $check += $row; - } - - $check %= 10; - $check = 10 - $check; - if ($check == $checksum) { - return true; - } - - return false; - } -} diff --git a/libs/Zend/Validate/Barcode/AdapterInterface.php b/libs/Zend/Validate/Barcode/AdapterInterface.php deleted file mode 100644 index 325c6048f3..0000000000 --- a/libs/Zend/Validate/Barcode/AdapterInterface.php +++ /dev/null @@ -1,68 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ - */ - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -interface Zend_Validate_Barcode_AdapterInterface -{ - /** - * Checks the length of a barcode - * - * @param string $value The barcode to check for proper length - * @return boolean - */ - public function checkLength($value); - - /** - * Checks for allowed characters within the barcode - * - * @param string $value The barcode to check for allowed characters - * @return boolean - */ - public function checkChars($value); - - /** - * Validates the checksum - * - * @param string $value The barcode to check the checksum for - * @return boolean - */ - public function checksum($value); - - /** - * Returns if barcode uses a checksum - * - * @return boolean - */ - public function getCheck(); - - /** - * Sets the checksum validation - * - * @param boolean $check - * @return Zend_Validate_Barcode_Adapter Provides fluid interface - */ - public function setCheck($check); -} diff --git a/libs/Zend/Validate/Barcode/Code25.php b/libs/Zend/Validate/Barcode/Code25.php deleted file mode 100644 index 6d1525da4c..0000000000 --- a/libs/Zend/Validate/Barcode/Code25.php +++ /dev/null @@ -1,64 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Code25 extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = -1; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_code25'; - - /** - * Constructor - * - * Sets check flag to false. - * - * @return void - */ - public function __construct() - { - $this->setCheck(false); - } -} diff --git a/libs/Zend/Validate/Barcode/Code25interleaved.php b/libs/Zend/Validate/Barcode/Code25interleaved.php deleted file mode 100644 index 54fd90bd28..0000000000 --- a/libs/Zend/Validate/Barcode/Code25interleaved.php +++ /dev/null @@ -1,64 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Code25interleaved extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = 'even'; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_code25'; - - /** - * Constructor - * - * Sets check flag to false. - * - * @return void - */ - public function __construct() - { - $this->setCheck(false); - } -} diff --git a/libs/Zend/Validate/Barcode/Code39.php b/libs/Zend/Validate/Barcode/Code39.php deleted file mode 100644 index 8208cffb9e..0000000000 --- a/libs/Zend/Validate/Barcode/Code39.php +++ /dev/null @@ -1,100 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Code39 extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = -1; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ -.$/+%'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_code39'; - - /** - * @var array - */ - protected $_check = array( - '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, - '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, - 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, - 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, - 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34, - 'Z' => 35, '-' => 36, '.' => 37, ' ' => 38, '$' => 39, '/' => 40, '+' => 41, - '%' => 42, - ); - - /** - * Constructor - * - * Sets check flag to false. - * - * @return void - */ - public function __construct() - { - $this->setCheck(false); - } - - /** - * Validates the checksum (Modulo 43) - * - * @param string $value The barcode to validate - * @return boolean - */ - protected function _code39($value) - { - $checksum = substr($value, -1, 1); - $value = str_split(substr($value, 0, -1)); - $count = 0; - foreach($value as $char) { - $count += $this->_check[$char]; - } - - $mod = $count % 43; - if ($mod == $this->_check[$checksum]) { - return true; - } - - return false; - } -} diff --git a/libs/Zend/Validate/Barcode/Code39ext.php b/libs/Zend/Validate/Barcode/Code39ext.php deleted file mode 100644 index 5b90254c50..0000000000 --- a/libs/Zend/Validate/Barcode/Code39ext.php +++ /dev/null @@ -1,58 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Code39ext extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = -1; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = 128; - - /** - * Constructor - * - * Sets check flag to false. - * - * @return void - */ - public function __construct() - { - $this->setCheck(false); - } -} diff --git a/libs/Zend/Validate/Barcode/Code93.php b/libs/Zend/Validate/Barcode/Code93.php deleted file mode 100644 index 36a6567f36..0000000000 --- a/libs/Zend/Validate/Barcode/Code93.php +++ /dev/null @@ -1,120 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Code93 extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = -1; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ -.$/+%'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_code93'; - - /** - * Note that the characters !"§& are only synonyms - * @var array - */ - protected $_check = array( - '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, - '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, - 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, - 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, - 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34, - 'Z' => 35, '-' => 36, '.' => 37, ' ' => 38, '$' => 39, '/' => 40, '+' => 41, - '%' => 42, '!' => 43, '"' => 44, '§' => 45, '&' => 46, - ); - - /** - * Constructor - * - * Sets check flag to false. - * - * @return void - */ - public function __construct() - { - $this->setCheck(false); - } - - /** - * Validates the checksum (Modulo CK) - * - * @param string $value The barcode to validate - * @return boolean - */ - protected function _code93($value) - { - $checksum = substr($value, -2, 2); - $value = str_split(substr($value, 0, -2)); - $count = 0; - $length = count($value) % 20; - foreach($value as $char) { - if ($length == 0) { - $length = 20; - } - - $count += $this->_check[$char] * $length; - --$length; - } - - $check = array_search(($count % 47), $this->_check); - $value[] = $check; - $count = 0; - $length = count($value) % 15; - foreach($value as $char) { - if ($length == 0) { - $length = 15; - } - - $count += $this->_check[$char] * $length; - --$length; - } - $check .= array_search(($count % 47), $this->_check); - - if ($check == $checksum) { - return true; - } - - return false; - } -} diff --git a/libs/Zend/Validate/Barcode/Code93ext.php b/libs/Zend/Validate/Barcode/Code93ext.php deleted file mode 100644 index 2aaf343162..0000000000 --- a/libs/Zend/Validate/Barcode/Code93ext.php +++ /dev/null @@ -1,58 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Code93ext extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = -1; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = 128; - - /** - * Constructor - * - * Sets check flag to false. - * - * @return void - */ - public function __construct() - { - $this->setCheck(false); - } -} diff --git a/libs/Zend/Validate/Barcode/Ean12.php b/libs/Zend/Validate/Barcode/Ean12.php deleted file mode 100644 index 26dee47fb5..0000000000 --- a/libs/Zend/Validate/Barcode/Ean12.php +++ /dev/null @@ -1,52 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Ean12 extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = 12; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_gtin'; -} diff --git a/libs/Zend/Validate/Barcode/Ean13.php b/libs/Zend/Validate/Barcode/Ean13.php index d5387e52f9..068809248c 100644 --- a/libs/Zend/Validate/Barcode/Ean13.php +++ b/libs/Zend/Validate/Barcode/Ean13.php @@ -1,4 +1,5 @@ <?php + /** * Zend Framework * @@ -14,39 +15,96 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Ean13.php 16223 2009-06-21 20:04:53Z thomas $ */ + /** - * @see Zend_Validate_Barcode_AdapterAbstract + * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; +require_once 'Zend/Validate/Abstract.php'; + /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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_Barcode_AdapterAbstract +class Zend_Validate_Barcode_Ean13 extends Zend_Validate_Abstract { /** - * Allowed barcode lengths - * @var integer + * 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 */ - protected $_length = 13; + const INVALID_LENGTH = 'invalidLength'; /** - * Allowed barcode characters - * @var string + * Validation failure message key for when the value + * does not only contain numeric characters */ - protected $_characters = '0123456789'; + const NOT_NUMERIC = 'ean13NotNumeric'; /** - * Checksum function - * @var string + * Validation failure message template definitions + * + * @var array */ - protected $_checksum = '_gtin'; + protected $_messageTemplates = array( + self::INVALID => "'%value%' is an invalid EAN-13 barcode", + self::INVALID_LENGTH => "'%value%' should be 13 characters", + self::NOT_NUMERIC => "'%value%' should contain only numeric 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) + { + if (!is_string($value) || !ctype_digit($value)) { + $this->_error(self::NOT_NUMERIC); + return false; + } + + $this->_setValue($value); + if (strlen($value) !== 13) { + $this->_error(self::INVALID_LENGTH); + return false; + } + + $barcode = strrev(substr($value, 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 ($value[12] != $checksum) { + $this->_error(self::INVALID); + return false; + } + + return true; + } } diff --git a/libs/Zend/Validate/Barcode/Ean14.php b/libs/Zend/Validate/Barcode/Ean14.php deleted file mode 100644 index 19756c8ee7..0000000000 --- a/libs/Zend/Validate/Barcode/Ean14.php +++ /dev/null @@ -1,52 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Ean14 extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = 14; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_gtin'; -} diff --git a/libs/Zend/Validate/Barcode/Ean18.php b/libs/Zend/Validate/Barcode/Ean18.php deleted file mode 100644 index 7c6519959f..0000000000 --- a/libs/Zend/Validate/Barcode/Ean18.php +++ /dev/null @@ -1,52 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Ean18 extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = 18; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_gtin'; -} diff --git a/libs/Zend/Validate/Barcode/Ean2.php b/libs/Zend/Validate/Barcode/Ean2.php deleted file mode 100644 index 009bfe5e57..0000000000 --- a/libs/Zend/Validate/Barcode/Ean2.php +++ /dev/null @@ -1,58 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Ean2 extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = 2; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Constructor - * - * Sets check flag to false. - * - * @return void - */ - public function __construct() - { - $this->setCheck(false); - } -} diff --git a/libs/Zend/Validate/Barcode/Ean5.php b/libs/Zend/Validate/Barcode/Ean5.php deleted file mode 100644 index 7574e897e4..0000000000 --- a/libs/Zend/Validate/Barcode/Ean5.php +++ /dev/null @@ -1,58 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Ean5 extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = 5; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Constructor - * - * Sets check flag to false. - * - * @return void - */ - public function __construct() - { - $this->setCheck(false); - } -} diff --git a/libs/Zend/Validate/Barcode/Ean8.php b/libs/Zend/Validate/Barcode/Ean8.php deleted file mode 100644 index ca68fe45d9..0000000000 --- a/libs/Zend/Validate/Barcode/Ean8.php +++ /dev/null @@ -1,69 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Ean8 extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = array(7, 8); - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_gtin'; - - /** - * Overrides parent checkLength - * - * @param string $value Value - * @return boolean - */ - public function checkLength($value) - { - if (strlen($value) == 7) { - $this->setCheck(false); - } else { - $this->setCheck(true); - } - - return parent::checkLength($value); - } -} diff --git a/libs/Zend/Validate/Barcode/Gtin12.php b/libs/Zend/Validate/Barcode/Gtin12.php deleted file mode 100644 index 7453e05f64..0000000000 --- a/libs/Zend/Validate/Barcode/Gtin12.php +++ /dev/null @@ -1,52 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Gtin12 extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = 12; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_gtin'; -} diff --git a/libs/Zend/Validate/Barcode/Gtin13.php b/libs/Zend/Validate/Barcode/Gtin13.php deleted file mode 100644 index c466f5896a..0000000000 --- a/libs/Zend/Validate/Barcode/Gtin13.php +++ /dev/null @@ -1,52 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Gtin13 extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = 13; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_gtin'; -} diff --git a/libs/Zend/Validate/Barcode/Gtin14.php b/libs/Zend/Validate/Barcode/Gtin14.php deleted file mode 100644 index 7c5c1cdb5b..0000000000 --- a/libs/Zend/Validate/Barcode/Gtin14.php +++ /dev/null @@ -1,52 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Gtin14 extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = 14; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_gtin'; -} diff --git a/libs/Zend/Validate/Barcode/Identcode.php b/libs/Zend/Validate/Barcode/Identcode.php deleted file mode 100644 index 6899c17910..0000000000 --- a/libs/Zend/Validate/Barcode/Identcode.php +++ /dev/null @@ -1,52 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Identcode extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = 12; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_identcode'; -} diff --git a/libs/Zend/Validate/Barcode/Intelligentmail.php b/libs/Zend/Validate/Barcode/Intelligentmail.php deleted file mode 100644 index a0e81cfca6..0000000000 --- a/libs/Zend/Validate/Barcode/Intelligentmail.php +++ /dev/null @@ -1,58 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_IntelligentMail extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = array(20, 25, 29, 31); - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Constructor - * - * Sets check flag to false. - * - * @return void - */ - public function __construct() - { - $this->setCheck(false); - } -} diff --git a/libs/Zend/Validate/Barcode/Issn.php b/libs/Zend/Validate/Barcode/Issn.php deleted file mode 100644 index e9507c9a5f..0000000000 --- a/libs/Zend/Validate/Barcode/Issn.php +++ /dev/null @@ -1,119 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Issn extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = array(8, 13); - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789X'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_gtin'; - - /** - * Allows X on length of 8 chars - * - * @param string $value The barcode to check for allowed characters - * @return boolean - */ - public function checkChars($value) - { - if (strlen($value) != 8) { - if (strpos($value, 'X') !== false) { - return false; - } - } - - return parent::checkChars($value); - } - - /** - * Validates the checksum - * - * @param string $value The barcode to check the checksum for - * @return boolean - */ - public function checksum($value) - { - if (strlen($value) == 8) { - $this->_checksum = '_issn'; - } else { - $this->_checksum = '_gtin'; - } - - return parent::checksum($value); - } - - /** - * Validates the checksum () - * ISSN implementation (reversed mod11) - * - * @param string $value The barcode to validate - * @return boolean - */ - protected function _issn($value) - { - $checksum = substr($value, -1, 1); - $values = str_split(substr($value, 0, -1)); - $check = 0; - $multi = 8; - foreach($values as $token) { - if ($token == 'X') { - $token = 10; - } - - $check += ($token * $multi); - --$multi; - } - - $check %= 11; - $check = 11 - $check; - if ($check == $checksum) { - return true; - } else if (($check == 10) && ($checksum == 'X')) { - return true; - } - - return false; - } -} diff --git a/libs/Zend/Validate/Barcode/Itf14.php b/libs/Zend/Validate/Barcode/Itf14.php deleted file mode 100644 index 10cfeb761c..0000000000 --- a/libs/Zend/Validate/Barcode/Itf14.php +++ /dev/null @@ -1,52 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Itf14 extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = 14; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_gtin'; -} diff --git a/libs/Zend/Validate/Barcode/Leitcode.php b/libs/Zend/Validate/Barcode/Leitcode.php deleted file mode 100644 index 52f1fc0428..0000000000 --- a/libs/Zend/Validate/Barcode/Leitcode.php +++ /dev/null @@ -1,52 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Leitcode extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = 14; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_identcode'; -} diff --git a/libs/Zend/Validate/Barcode/Planet.php b/libs/Zend/Validate/Barcode/Planet.php deleted file mode 100644 index b4eaf66cb9..0000000000 --- a/libs/Zend/Validate/Barcode/Planet.php +++ /dev/null @@ -1,52 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Planet extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = array(12, 14); - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_postnet'; -} diff --git a/libs/Zend/Validate/Barcode/Postnet.php b/libs/Zend/Validate/Barcode/Postnet.php deleted file mode 100644 index 9d2ff879b8..0000000000 --- a/libs/Zend/Validate/Barcode/Postnet.php +++ /dev/null @@ -1,52 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Postnet extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = array(6, 7, 10, 12); - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_postnet'; -} diff --git a/libs/Zend/Validate/Barcode/Royalmail.php b/libs/Zend/Validate/Barcode/Royalmail.php deleted file mode 100644 index 0bcdf1e16c..0000000000 --- a/libs/Zend/Validate/Barcode/Royalmail.php +++ /dev/null @@ -1,121 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Royalmail extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = -1; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; - - protected $_rows = array( - '0' => 1, '1' => 1, '2' => 1, '3' => 1, '4' => 1, '5' => 1, - '6' => 2, '7' => 2, '8' => 2, '9' => 2, 'A' => 2, 'B' => 2, - 'C' => 3, 'D' => 3, 'E' => 3, 'F' => 3, 'G' => 3, 'H' => 3, - 'I' => 4, 'J' => 4, 'K' => 4, 'L' => 4, 'M' => 4, 'N' => 4, - 'O' => 5, 'P' => 5, 'Q' => 5, 'R' => 5, 'S' => 5, 'T' => 5, - 'U' => 0, 'V' => 0, 'W' => 0, 'X' => 0, 'Y' => 0, 'Z' => 0, - ); - - protected $_columns = array( - '0' => 1, '1' => 2, '2' => 3, '3' => 4, '4' => 5, '5' => 0, - '6' => 1, '7' => 2, '8' => 3, '9' => 4, 'A' => 5, 'B' => 0, - 'C' => 1, 'D' => 2, 'E' => 3, 'F' => 4, 'G' => 5, 'H' => 0, - 'I' => 1, 'J' => 2, 'K' => 3, 'L' => 4, 'M' => 5, 'N' => 0, - 'O' => 1, 'P' => 2, 'Q' => 3, 'R' => 4, 'S' => 5, 'T' => 0, - 'U' => 1, 'V' => 2, 'W' => 3, 'X' => 4, 'Y' => 5, 'Z' => 0, - ); - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_royalmail'; - - /** - * Validates the checksum () - * - * @param string $value The barcode to validate - * @return boolean - */ - protected function _royalmail($value) - { - $checksum = substr($value, -1, 1); - $values = str_split(substr($value, 0, -1)); - $rowvalue = 0; - $colvalue = 0; - foreach($values as $row) { - $rowvalue += $this->_rows[$row]; - $colvalue += $this->_columns[$row]; - } - - $rowvalue %= 6; - $colvalue %= 6; - - $rowchkvalue = array_keys($this->_rows, $rowvalue); - $colchkvalue = array_keys($this->_columns, $colvalue); - $chkvalue = current(array_intersect($rowchkvalue, $colchkvalue)); - if ($chkvalue == $checksum) { - return true; - } - - return false; - } - - /** - * Allows start and stop tag within checked chars - * - * @param string $value The barcode to check for allowed characters - * @return boolean - */ - public function checkChars($value) - { - if ($value[0] == '(') { - $value = substr($value, 1); - - if ($value[strlen($value) - 1] == ')') { - $value = substr($value, 0, -1); - } else { - return false; - } - } - - return parent::checkChars($value); - } -} diff --git a/libs/Zend/Validate/Barcode/Sscc.php b/libs/Zend/Validate/Barcode/Sscc.php deleted file mode 100644 index b44b19a561..0000000000 --- a/libs/Zend/Validate/Barcode/Sscc.php +++ /dev/null @@ -1,52 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Sscc extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = 18; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_gtin'; -} diff --git a/libs/Zend/Validate/Barcode/UpcA.php b/libs/Zend/Validate/Barcode/UpcA.php new file mode 100644 index 0000000000..cf33f31fab --- /dev/null +++ b/libs/Zend/Validate/Barcode/UpcA.php @@ -0,0 +1,103 @@ +<?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-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: UpcA.php 16223 2009-06-21 20:04:53Z thomas $ + */ + + +/** + * @see Zend_Validate_Abstract + */ +require_once 'Zend/Validate/Abstract.php'; + + +/** + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-2009 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) + { + if (!is_string($value)) { + $this->_error(self::INVALID); + return false; + } + + $this->_setValue($value); + if (strlen($value) !== 12) { + $this->_error(self::INVALID_LENGTH); + return false; + } + + $barcode = substr($value, 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 ($value[11] != $checksum) { + $this->_error(self::INVALID); + return false; + } + + return true; + } +} diff --git a/libs/Zend/Validate/Barcode/Upca.php b/libs/Zend/Validate/Barcode/Upca.php deleted file mode 100644 index 2f0411ef95..0000000000 --- a/libs/Zend/Validate/Barcode/Upca.php +++ /dev/null @@ -1,52 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Upca.php 20096 2010-01-06 02:05:09Z bkarwin $ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 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_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = 12; - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_gtin'; -} diff --git a/libs/Zend/Validate/Barcode/Upce.php b/libs/Zend/Validate/Barcode/Upce.php deleted file mode 100644 index 3199f19b90..0000000000 --- a/libs/Zend/Validate/Barcode/Upce.php +++ /dev/null @@ -1,69 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: UpcA.php 18028 2009-09-08 20:52:23Z thomas $ - */ - -/** - * @see Zend_Validate_Barcode_AdapterAbstract - */ -// require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Barcode_Upce extends Zend_Validate_Barcode_AdapterAbstract -{ - /** - * Allowed barcode lengths - * @var integer - */ - protected $_length = array(6, 7, 8); - - /** - * Allowed barcode characters - * @var string - */ - protected $_characters = '0123456789'; - - /** - * Checksum function - * @var string - */ - protected $_checksum = '_gtin'; - - /** - * Overrides parent checkLength - * - * @param string $value Value - * @return boolean - */ - public function checkLength($value) - { - if (strlen($value) != 8) { - $this->setCheck(false); - } else { - $this->setCheck(true); - } - - return parent::checkLength($value); - } -} diff --git a/libs/Zend/Validate/Between.php b/libs/Zend/Validate/Between.php index 7245295dbb..b9fd7c2dc6 100644 --- a/libs/Zend/Validate/Between.php +++ b/libs/Zend/Validate/Between.php @@ -1,4 +1,5 @@ <?php + /** * Zend Framework * @@ -14,20 +15,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Between.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Between.php 16223 2009-06-21 20:04:53Z thomas $ */ + /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; + /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 @@ -88,44 +91,17 @@ class Zend_Validate_Between extends Zend_Validate_Abstract /** * Sets validator options - * Accepts the following option keys: - * 'min' => scalar, minimum border - * 'max' => scalar, maximum border - * 'inclusive' => boolean, inclusive border values * - * @param array|Zend_Config $options + * @param mixed $min + * @param mixed $max + * @param boolean $inclusive * @return void */ - public function __construct($options) + public function __construct($min, $max, $inclusive = true) { - if ($options instanceof Zend_Config) { - $options = $options->toArray(); - } else if (!is_array($options)) { - $options = func_get_args(); - $temp['min'] = array_shift($options); - if (!empty($options)) { - $temp['max'] = array_shift($options); - } - - if (!empty($options)) { - $temp['inclusive'] = array_shift($options); - } - - $options = $temp; - } - - if (!array_key_exists('min', $options) || !array_key_exists('max', $options)) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception("Missing option. 'min' and 'max' has to be given"); - } - - if (!array_key_exists('inclusive', $options)) { - $options['inclusive'] = true; - } - - $this->setMin($options['min']) - ->setMax($options['max']) - ->setInclusive($options['inclusive']); + $this->setMin($min) + ->setMax($max) + ->setInclusive($inclusive); } /** diff --git a/libs/Zend/Validate/Callback.php b/libs/Zend/Validate/Callback.php deleted file mode 100644 index 398e27324c..0000000000 --- a/libs/Zend/Validate/Callback.php +++ /dev/null @@ -1,174 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Callback.php 20096 2010-01-06 02:05:09Z bkarwin $ - */ - -/** - * @see Zend_Validate_Abstract - */ -// require_once 'Zend/Validate/Abstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Callback extends Zend_Validate_Abstract -{ - /** - * Invalid callback - */ - const INVALID_CALLBACK = 'callbackInvalid'; - - /** - * Invalid value - */ - const INVALID_VALUE = 'callbackValue'; - - /** - * Validation failure message template definitions - * - * @var array - */ - protected $_messageTemplates = array( - self::INVALID_VALUE => "'%value%' is not valid", - self::INVALID_CALLBACK => "Failure within the callback, exception returned", - ); - - /** - * Callback in a call_user_func format - * - * @var string|array - */ - protected $_callback = null; - - /** - * Default options to set for the filter - * - * @var mixed - */ - protected $_options = array(); - - /** - * Sets validator options - * - * @param string|array $callback - * @param mixed $max - * @param boolean $inclusive - * @return void - */ - public function __construct($callback = null) - { - if (is_callable($callback)) { - $this->setCallback($callback); - } elseif (is_array($callback)) { - if (isset($callback['callback'])) { - $this->setCallback($callback['callback']); - } - if (isset($callback['options'])) { - $this->setOptions($callback['options']); - } - } - - if (null === ($initializedCallack = $this->getCallback())) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('No callback registered'); - } - } - - /** - * Returns the set callback - * - * @return mixed - */ - public function getCallback() - { - return $this->_callback; - } - - /** - * Sets the callback - * - * @param string|array $callback - * @return Zend_Validate_Callback Provides a fluent interface - */ - public function setCallback($callback) - { - if (!is_callable($callback)) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('Invalid callback given'); - } - $this->_callback = $callback; - return $this; - } - - /** - * Returns the set options for the callback - * - * @return mixed - */ - public function getOptions() - { - return $this->_options; - } - - /** - * Sets options for the callback - * - * @param mixed $max - * @return Zend_Validate_Callback Provides a fluent interface - */ - public function setOptions($options) - { - $this->_options = (array) $options; - return $this; - } - - /** - * Defined by Zend_Validate_Interface - * - * Returns true if and only if the set callback returns - * for the provided $value - * - * @param mixed $value - * @return boolean - */ - public function isValid($value) - { - $this->_setValue($value); - - $options = $this->getOptions(); - $callback = $this->getCallback(); - $args = func_get_args(); - $options = array_merge($args, $options); - - try { - if (!call_user_func_array($callback, $options)) { - $this->_error(self::INVALID_VALUE); - return false; - } - } catch (Exception $e) { - $this->_error(self::INVALID_CALLBACK); - return false; - } - - return true; - } -} diff --git a/libs/Zend/Validate/Ccnum.php b/libs/Zend/Validate/Ccnum.php index 8c2a8beb14..489573c48d 100644 --- a/libs/Zend/Validate/Ccnum.php +++ b/libs/Zend/Validate/Ccnum.php @@ -1,4 +1,5 @@ <?php + /** * Zend Framework * @@ -14,20 +15,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ccnum.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Ccnum.php 16223 2009-06-21 20:04:53Z thomas $ */ + /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; + /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 @@ -59,11 +62,6 @@ class Zend_Validate_Ccnum extends Zend_Validate_Abstract self::CHECKSUM => "Luhn algorithm (mod-10 checksum) failed on '%value%'" ); - public function __construct() - { - trigger_error('Using the Ccnum validator is deprecated in favor of the CreditCard validator'); - } - /** * Defined by Zend_Validate_Interface * @@ -80,7 +78,7 @@ class Zend_Validate_Ccnum extends Zend_Validate_Abstract /** * @see Zend_Filter_Digits */ - // require_once 'Zend/Filter/Digits.php'; + require_once 'Zend/Filter/Digits.php'; self::$_filter = new Zend_Filter_Digits(); } @@ -109,4 +107,5 @@ class Zend_Validate_Ccnum extends Zend_Validate_Abstract return true; } + } diff --git a/libs/Zend/Validate/CreditCard.php b/libs/Zend/Validate/CreditCard.php deleted file mode 100644 index 9c8c039718..0000000000 --- a/libs/Zend/Validate/CreditCard.php +++ /dev/null @@ -1,317 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: CreditCard.php 21570 2010-03-19 19:00:50Z thomas $ - */ - -/** - * @see Zend_Validate_Abstract - */ -// require_once 'Zend/Validate/Abstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_CreditCard extends Zend_Validate_Abstract -{ - /** - * Detected CCI list - * - * @var string - */ - const ALL = 'All'; - const AMERICAN_EXPRESS = 'American_Express'; - const UNIONPAY = 'Unionpay'; - const DINERS_CLUB = 'Diners_Club'; - const DINERS_CLUB_US = 'Diners_Club_US'; - const DISCOVER = 'Discover'; - const JCB = 'JCB'; - const LASER = 'Laser'; - const MAESTRO = 'Maestro'; - const MASTERCARD = 'Mastercard'; - const SOLO = 'Solo'; - const VISA = 'Visa'; - - const CHECKSUM = 'creditcardChecksum'; - const CONTENT = 'creditcardContent'; - const INVALID = 'creditcardInvalid'; - const LENGTH = 'creditcardLength'; - const PREFIX = 'creditcardPrefix'; - const SERVICE = 'creditcardService'; - const SERVICEFAILURE = 'creditcardServiceFailure'; - - /** - * Validation failure message template definitions - * - * @var array - */ - protected $_messageTemplates = array( - self::CHECKSUM => "Luhn algorithm (mod-10 checksum) failed on '%value%'", - self::CONTENT => "'%value%' must contain only digits", - self::INVALID => "Invalid type given, value should be a string", - self::LENGTH => "'%value%' contains an invalid amount of digits", - self::PREFIX => "'%value%' is not from an allowed institute", - self::SERVICE => "Validation of '%value%' has been failed by the service", - self::SERVICEFAILURE => "The service returned a failure while validating '%value%'", - ); - - /** - * List of allowed CCV lengths - * - * @var array - */ - protected $_cardLength = array( - self::AMERICAN_EXPRESS => array(15), - self::DINERS_CLUB => array(14), - self::DINERS_CLUB_US => array(16), - self::DISCOVER => array(16), - self::JCB => array(16), - self::LASER => array(16, 17, 18, 19), - self::MAESTRO => array(12, 13, 14, 15, 16, 17, 18, 19), - self::MASTERCARD => array(16), - self::SOLO => array(16, 18, 19), - self::UNIONPAY => array(16, 17, 18, 19), - self::VISA => array(16), - ); - - /** - * List of accepted CCV provider tags - * - * @var array - */ - protected $_cardType = array( - self::AMERICAN_EXPRESS => array('34', '37'), - self::DINERS_CLUB => array('300', '301', '302', '303', '304', '305', '36'), - self::DINERS_CLUB_US => array('54', '55'), - self::DISCOVER => array('6011', '622126', '622127', '622128', '622129', '62213', - '62214', '62215', '62216', '62217', '62218', '62219', - '6222', '6223', '6224', '6225', '6226', '6227', '6228', - '62290', '62291', '622920', '622921', '622922', '622923', - '622924', '622925', '644', '645', '646', '647', '648', - '649', '65'), - self::JCB => array('3528', '3529', '353', '354', '355', '356', '357', '358'), - self::LASER => array('6304', '6706', '6771', '6709'), - self::MAESTRO => array('5018', '5020', '5038', '6304', '6759', '6761', '6763'), - self::MASTERCARD => array('51', '52', '53', '54', '55'), - self::SOLO => array('6334', '6767'), - self::UNIONPAY => array('622126', '622127', '622128', '622129', '62213', '62214', - '62215', '62216', '62217', '62218', '62219', '6222', '6223', - '6224', '6225', '6226', '6227', '6228', '62290', '62291', - '622920', '622921', '622922', '622923', '622924', '622925'), - self::VISA => array('4'), - ); - - /** - * CCIs which are accepted by validation - * - * @var array - */ - protected $_type = array(); - - /** - * Service callback for additional validation - * - * @var callback - */ - protected $_service; - - /** - * Constructor - * - * @param string|array $type OPTIONAL Type of CCI to allow - */ - public function __construct($options = array()) - { - if ($options instanceof Zend_Config) { - $options = $options->toArray(); - } else if (!is_array($options)) { - $options = func_get_args(); - $temp['type'] = array_shift($options); - if (!empty($options)) { - $temp['service'] = array_shift($options); - } - - $options = $temp; - } - - if (!array_key_exists('type', $options)) { - $options['type'] = self::ALL; - } - - $this->setType($options['type']); - if (array_key_exists('service', $options)) { - $this->setService($options['service']); - } - } - - /** - * Returns a list of accepted CCIs - * - * @return array - */ - public function getType() - { - return $this->_type; - } - - /** - * Sets CCIs which are accepted by validation - * - * @param string|array $type Type to allow for validation - * @return Zend_Validate_CreditCard Provides a fluid interface - */ - public function setType($type) - { - $this->_type = array(); - return $this->addType($type); - } - - /** - * Adds a CCI to be accepted by validation - * - * @param string|array $type Type to allow for validation - * @return Zend_Validate_CreditCard Provides a fluid interface - */ - public function addType($type) - { - if (is_string($type)) { - $type = array($type); - } - - foreach($type as $typ) { - if (defined('self::' . strtoupper($typ)) && !in_array($typ, $this->_type)) { - $this->_type[] = $typ; - } - - if (($typ == self::ALL)) { - $this->_type = array_keys($this->_cardLength); - } - } - - return $this; - } - - /** - * Returns the actual set service - * - * @return callback - */ - public function getService() - { - return $this->_service; - } - - /** - * Sets a new callback for service validation - * - * @param unknown_type $service - */ - public function setService($service) - { - if (!is_callable($service)) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('Invalid callback given'); - } - - $this->_service = $service; - return $this; - } - - /** - * 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 (!is_string($value)) { - $this->_error(self::INVALID, $value); - return false; - } - - if (!ctype_digit($value)) { - $this->_error(self::CONTENT, $value); - return false; - } - - $length = strlen($value); - $types = $this->getType(); - $foundp = false; - $foundl = false; - foreach ($types as $type) { - foreach ($this->_cardType[$type] as $prefix) { - if (substr($value, 0, strlen($prefix)) == $prefix) { - $foundp = true; - if (in_array($length, $this->_cardLength[$type])) { - $foundl = true; - break 2; - } - } - } - } - - if ($foundp == false){ - $this->_error(self::PREFIX, $value); - return false; - } - - if ($foundl == false) { - $this->_error(self::LENGTH, $value); - return false; - } - - $sum = 0; - $weight = 2; - - for ($i = $length - 2; $i >= 0; $i--) { - $digit = $weight * $value[$i]; - $sum += floor($digit / 10) + $digit % 10; - $weight = $weight % 2 + 1; - } - - if ((10 - $sum % 10) % 10 != $value[$length - 1]) { - $this->_error(self::CHECKSUM, $value); - return false; - } - - if (!empty($this->_service)) { - try { - // require_once 'Zend/Validate/Callback.php'; - $callback = new Zend_Validate_Callback($this->_service); - $callback->setOptions($this->_type); - if (!$callback->isValid($value)) { - $this->_error(self::SERVICE, $value); - return false; - } - } catch (Zend_Exception $e) { - $this->_error(self::SERVICEFAILURE, $value); - return false; - } - } - - return true; - } -} diff --git a/libs/Zend/Validate/Date.php b/libs/Zend/Validate/Date.php index 22e49b7aee..5dbcc6d702 100644 --- a/libs/Zend/Validate/Date.php +++ b/libs/Zend/Validate/Date.php @@ -14,26 +14,27 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Date.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: Date.php 17696 2009-08-20 20:12:33Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 { const INVALID = 'dateInvalid'; - const INVALID_DATE = 'dateInvalidDate'; + const NOT_YYYY_MM_DD = 'dateNotYYYY-MM-DD'; + const INVALID_DATE = 'dateInvalidDate'; const FALSEFORMAT = 'dateFalseFormat'; /** @@ -43,15 +44,9 @@ class Zend_Validate_Date extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be string, integer, array or Zend_Date", + self::NOT_YYYY_MM_DD => "'%value%' is not of the format YYYY-MM-DD", self::INVALID_DATE => "'%value%' does not appear to be a valid date", - self::FALSEFORMAT => "'%value%' does not fit the date format '%format%'", - ); - - /** - * @var array - */ - protected $_messageVariables = array( - 'format' => '_format' + self::FALSEFORMAT => "'%value%' does not fit given date format" ); /** @@ -71,36 +66,22 @@ class Zend_Validate_Date extends Zend_Validate_Abstract /** * Sets validator options * - * @param string|Zend_Config $options OPTIONAL + * @param string $format OPTIONAL + * @param string|Zend_Locale $locale OPTIONAL * @return void */ - public function __construct($options = array()) + public function __construct($format = null, $locale = null) { - if ($options instanceof Zend_Config) { - $options = $options->toArray(); - } else if (!is_array($options)) { - $options = func_get_args(); - $temp['format'] = array_shift($options); - if (!empty($options)) { - $temp['locale'] = array_shift($options); - } - - $options = $temp; - } - - if (array_key_exists('format', $options)) { - $this->setFormat($options['format']); - } - - if (!array_key_exists('locale', $options)) { - // require_once 'Zend/Registry.php'; + $this->setFormat($format); + if ($locale === null) { + require_once 'Zend/Registry.php'; if (Zend_Registry::isRegistered('Zend_Locale')) { - $options['locale'] = Zend_Registry::get('Zend_Locale'); + $locale = Zend_Registry::get('Zend_Locale'); } } - if (array_key_exists('locale', $options)) { - $this->setLocale($options['locale']); + if ($locale !== null) { + $this->setLocale($locale); } } @@ -122,7 +103,7 @@ class Zend_Validate_Date extends Zend_Validate_Abstract */ public function setLocale($locale = null) { - // require_once 'Zend/Locale.php'; + require_once 'Zend/Locale.php'; $this->_locale = Zend_Locale::findLocale($locale); return $this; } @@ -171,7 +152,7 @@ class Zend_Validate_Date extends Zend_Validate_Abstract if (($this->_format !== null) || ($this->_locale !== null) || is_array($value) || $value instanceof Zend_Date) { - // require_once 'Zend/Date.php'; + require_once 'Zend/Date.php'; if (!Zend_Date::isDate($value, $this->_format, $this->_locale)) { if ($this->_checkFormat($value) === false) { $this->_error(self::FALSEFORMAT); @@ -182,9 +163,7 @@ class Zend_Validate_Date extends Zend_Validate_Abstract } } else { if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) { - $this->_format = 'yyyy-MM-dd'; - $this->_error(self::FALSEFORMAT); - $this->_format = null; + $this->_error(self::NOT_YYYY_MM_DD); return false; } @@ -208,7 +187,7 @@ class Zend_Validate_Date extends Zend_Validate_Abstract private function _checkFormat($value) { try { - // require_once 'Zend/Locale/Format.php'; + require_once 'Zend/Locale/Format.php'; $parsed = Zend_Locale_Format::getDate($value, array( 'date_format' => $this->_format, 'format_type' => 'iso', 'fix_date' => false)); diff --git a/libs/Zend/Validate/Db/Abstract.php b/libs/Zend/Validate/Db/Abstract.php index 5811c495a9..e5103ff4ed 100644 --- a/libs/Zend/Validate/Db/Abstract.php +++ b/libs/Zend/Validate/Db/Abstract.php @@ -1,4 +1,5 @@ -<?php +<?php + /** * Zend Framework * @@ -14,285 +15,134 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Abstract.php 22225 2010-05-21 09:12:52Z bittarman $ - */ - + * @version $Id: Abstract.php 17160 2009-07-26 19:46:24Z bittarman $ + */ + /** * @see Zend_Validate_Abstract - */ -// require_once 'Zend/Validate/Abstract.php'; - + */ +require_once 'Zend/Validate/Abstract.php'; + /** * Class for Database record validation - * + * * @category Zend * @package Zend_Validate * @uses Zend_Validate_Abstract - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - */ -abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract -{ + */ +abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract +{ /** * Error constants - */ - const ERROR_NO_RECORD_FOUND = 'noRecordFound'; - const ERROR_RECORD_FOUND = 'recordFound'; - + */ + const ERROR_NO_RECORD_FOUND = 'noRecordFound'; + const ERROR_RECORD_FOUND = 'recordFound'; + /** * @var array Message templates - */ - protected $_messageTemplates = array( - self::ERROR_NO_RECORD_FOUND => 'No record matching %value% was found', - self::ERROR_RECORD_FOUND => 'A record matching %value% was found', - ); + */ + protected $_messageTemplates = array(self::ERROR_NO_RECORD_FOUND => 'No record matching %value% was found', + self::ERROR_RECORD_FOUND => 'A record matching %value% was found'); /** * @var string - */ + */ protected $_schema = null; - + /** * @var string - */ - protected $_table = ''; - + */ + protected $_table = ''; + /** * @var string - */ - protected $_field = ''; - + */ + protected $_field = ''; + /** * @var mixed - */ - protected $_exclude = null; - + */ + protected $_exclude = null; + /** * Database adapter to use. If null isValid() will use Zend_Db::getInstance instead * * @var unknown_type - */ - protected $_adapter = null; - + */ + protected $_adapter = null; + /** - * Provides basic configuration for use with Zend_Validate_Db Validators + * Provides basic configuration for use with Zend_Validate_Db Validators * Setting $exclude allows a single record to be excluded from matching. * Exclude can either be a String containing a where clause, or an array with `field` and `value` keys - * to define the where clause added to the sql. - * A database adapter may optionally be supplied to avoid using the registered default adapter. - * - * The following option keys are supported: - * 'table' => The database table to validate against - * 'schema' => The schema keys - * 'field' => The field to check for a match - * 'exclude' => An optional where clause or field/value pair to exclude from the query - * 'adapter' => An optional database adapter to use - * - * @param array|Zend_Config $options Options to use for this validator - */ - public function __construct($options) - { - if ($options instanceof Zend_Config) { - $options = $options->toArray(); - } else if (func_num_args() > 1) { - $options = func_get_args(); - $temp['table'] = array_shift($options); - $temp['field'] = array_shift($options); - if (!empty($options)) { - $temp['exclude'] = array_shift($options); - } - - if (!empty($options)) { - $temp['adapter'] = array_shift($options); - } - - $options = $temp; - } - - if (!array_key_exists('table', $options) && !array_key_exists('schema', $options)) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('Table or Schema option missing!'); - } - - if (!array_key_exists('field', $options)) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('Field option missing!'); - } - - if (array_key_exists('adapter', $options)) { - $this->setAdapter($options['adapter']); - } - - if (array_key_exists('exclude', $options)) { - $this->setExclude($options['exclude']); - } - - $this->setField($options['field']); - if (array_key_exists('table', $options)) { - $this->setTable($options['table']); - } - - if (array_key_exists('schema', $options)) { - $this->setSchema($options['schema']); + * to define the where clause added to the sql. + * A database adapter may optionally be supplied to avoid using the registered default adapter. + * + * @param string||array $table The database table to validate against, or array with table and schema keys + * @param string $field The field to check for a match + * @param string||array $exclude An optional where clause or field/value pair to exclude from the query + * @param Zend_Db_Adapter_Abstract $adapter An optional database adapter to use. + */ + public function __construct($table, $field, $exclude = null, Zend_Db_Adapter_Abstract $adapter = null) + { + if ($adapter !== null) { + $this->_adapter = $adapter; + } + $this->_exclude = $exclude; + $this->_field = (string) $field; + + if (is_array($table)) { + $this->_table = (isset($table['table'])) ? $table['table'] : ''; + $this->_schema = (isset($table['schema'])) ? $table['schema'] : null; + } else { + $this->_table = (string) $table; } - } - - /** - * Returns the set adapter - * - * @return Zend_Db_Adapter - */ - public function getAdapter() - { - return $this->_adapter; - } - - /** - * Sets a new database adapter - * - * @param Zend_Db_Adapter_Abstract $adapter - * @return Zend_Validate_Db_Abstract - */ - public function setAdapter($adapter) - { - if (!($adapter instanceof Zend_Db_Adapter_Abstract)) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('Adapter option must be a database adapter!'); - } - - $this->_adapter = $adapter; - return $this; - } - - /** - * Returns the set exclude clause - * - * @return string|array - */ - public function getExclude() - { - return $this->_exclude; - } - - /** - * Sets a new exclude clause - * - * @param string|array $exclude - * @return Zend_Validate_Db_Abstract - */ - public function setExclude($exclude) - { - $this->_exclude = $exclude; - return $this; - } - - /** - * Returns the set field - * - * @return string|array - */ - public function getField() - { - return $this->_field; - } - - /** - * Sets a new field - * - * @param string $field - * @return Zend_Validate_Db_Abstract - */ - public function setField($field) - { - $this->_field = (string) $field; - return $this; - } - - /** - * Returns the set table - * - * @return string - */ - public function getTable() - { - return $this->_table; - } - - /** - * Sets a new table - * - * @param string $table - * @return Zend_Validate_Db_Abstract - */ - public function setTable($table) - { - $this->_table = (string) $table; - return $this; - } - - /** - * Returns the set schema - * - * @return string - */ - public function getSchema() - { - return $this->_schema; - } - - /** - * Sets a new schema - * - * @param string $schema - * @return Zend_Validate_Db_Abstract - */ - public function setSchema($schema) - { - $this->_schema = $schema; - return $this; - } + } + /** * Run query and returns matches, or null if no matches are found. * * @param String $value * @return Array when matches are found. - */ - protected function _query($value) - { + */ + protected function _query($value) + { /** * Check for an adapter being defined. if not, fetch the default adapter. - */ + */ if ($this->_adapter === null) { $this->_adapter = Zend_Db_Table_Abstract::getDefaultAdapter(); if (null === $this->_adapter) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception('No database adapter present'); } } /** * Build select object - */ + */ $select = new Zend_Db_Select($this->_adapter); $select->from($this->_table, array($this->_field), $this->_schema) - ->where($this->_adapter->quoteIdentifier($this->_field, true).' = ?', $value); - if ($this->_exclude !== null) { - if (is_array($this->_exclude)) { - $select->where($this->_adapter->quoteIdentifier($this->_exclude['field'], true).' != ?', $this->_exclude['value']); - } else { - $select->where($this->_exclude); - } - } - $select->limit(1); - + ->where($this->_adapter->quoteIdentifier($this->_field).' = ?', $value); + if ($this->_exclude !== null) { + if (is_array($this->_exclude)) { + $select->where($this->_adapter->quoteIdentifier($this->_exclude['field']).' != ?', $this->_exclude['value']); + } else { + $select->where($this->_exclude); + } + } + $select->limit(1); + /** * Run query - */ - $result = $this->_adapter->fetchRow($select, array(), Zend_Db::FETCH_ASSOC); - - return $result; - } + */ + $result = $this->_adapter->fetchRow($select, array(), Zend_Db::FETCH_ASSOC); + + return $result; + } } diff --git a/libs/Zend/Validate/Db/NoRecordExists.php b/libs/Zend/Validate/Db/NoRecordExists.php index 700102e436..e9c0db49a8 100644 --- a/libs/Zend/Validate/Db/NoRecordExists.php +++ b/libs/Zend/Validate/Db/NoRecordExists.php @@ -1,4 +1,5 @@ <?php + /** * Zend Framework * @@ -14,15 +15,15 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: NoRecordExists.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: NoRecordExists.php 16971 2009-07-22 18:05:45Z mikaelkael $ */ /** * @see Zend_Validate_Db_Abstract */ -// require_once 'Zend/Validate/Db/Abstract.php'; +require_once 'Zend/Validate/Db/Abstract.php'; /** * Confirms a record does not exist in a table. @@ -30,7 +31,7 @@ * @category Zend * @package Zend_Validate * @uses Zend_Validate_Db_Abstract - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_Db_NoRecordExists extends Zend_Validate_Db_Abstract diff --git a/libs/Zend/Validate/Db/RecordExists.php b/libs/Zend/Validate/Db/RecordExists.php index bf96b96f5c..2d753e4b0a 100644 --- a/libs/Zend/Validate/Db/RecordExists.php +++ b/libs/Zend/Validate/Db/RecordExists.php @@ -1,4 +1,5 @@ <?php + /** * Zend Framework * @@ -14,38 +15,39 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: RecordExists.php 20096 2010-01-06 02:05:09Z bkarwin $ - */ - + * @version $Id: RecordExists.php 16971 2009-07-22 18:05:45Z mikaelkael $ + */ + + /** * @see Zend_Validate_Db_Abstract - */ -// require_once 'Zend/Validate/Db/Abstract.php'; - + */ +require_once 'Zend/Validate/Db/Abstract.php'; + /** * Confirms a record exists in a table. - * + * * @category Zend * @package Zend_Validate * @uses Zend_Validate_Db_Abstract - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Db_RecordExists extends Zend_Validate_Db_Abstract -{ - public function isValid($value) - { - $valid = true; - $this->_setValue($value); - - $result = $this->_query($value); - if (!$result) { - $valid = false; - $this->_error(self::ERROR_NO_RECORD_FOUND); - } - - return $valid; - } + */ +class Zend_Validate_Db_RecordExists extends Zend_Validate_Db_Abstract +{ + public function isValid($value) + { + $valid = true; + $this->_setValue($value); + + $result = $this->_query($value); + if (!$result) { + $valid = false; + $this->_error(self::ERROR_NO_RECORD_FOUND); + } + + return $valid; + } } diff --git a/libs/Zend/Validate/Digits.php b/libs/Zend/Validate/Digits.php index 9194568e27..12e6c4e454 100644 --- a/libs/Zend/Validate/Digits.php +++ b/libs/Zend/Validate/Digits.php @@ -1,4 +1,5 @@ <?php + /** * Zend Framework * @@ -14,26 +15,28 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Digits.php 21136 2010-02-22 22:30:50Z thomas $ + * @version $Id: Digits.php 16933 2009-07-21 20:24:35Z matthew $ */ + /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; + /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 { const NOT_DIGITS = 'notDigits'; - const STRING_EMPTY = 'digitsStringEmpty'; + const STRING_EMPTY = 'stringEmpty'; const INVALID = 'digitsInvalid'; /** @@ -49,7 +52,7 @@ class Zend_Validate_Digits extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_DIGITS => "'%value%' contains characters which are not digits; but only digits are allowed", + self::NOT_DIGITS => "'%value%' contains not only digit characters", self::STRING_EMPTY => "'%value%' is an empty string", self::INVALID => "Invalid type given, value should be string, integer or float", ); @@ -77,7 +80,7 @@ class Zend_Validate_Digits extends Zend_Validate_Abstract } if (null === self::$_filter) { - // require_once 'Zend/Filter/Digits.php'; + require_once 'Zend/Filter/Digits.php'; self::$_filter = new Zend_Filter_Digits(); } @@ -88,4 +91,5 @@ class Zend_Validate_Digits extends Zend_Validate_Abstract return true; } + } diff --git a/libs/Zend/Validate/EmailAddress.php b/libs/Zend/Validate/EmailAddress.php index c008dcfe9f..4948bb83f3 100644 --- a/libs/Zend/Validate/EmailAddress.php +++ b/libs/Zend/Validate/EmailAddress.php @@ -14,25 +14,25 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: EmailAddress.php 21461 2010-03-10 22:34:03Z thomas $ + * @version $Id: EmailAddress.php 16223 2009-06-21 20:04:53Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * @see Zend_Validate_Hostname */ -// require_once 'Zend/Validate/Hostname.php'; +require_once 'Zend/Validate/Hostname.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 @@ -41,7 +41,6 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract const INVALID_FORMAT = 'emailAddressInvalidFormat'; const INVALID_HOSTNAME = 'emailAddressInvalidHostname'; const INVALID_MX_RECORD = 'emailAddressInvalidMxRecord'; - const INVALID_SEGMENT = 'emailAddressInvalidSegment'; const DOT_ATOM = 'emailAddressDotAtom'; const QUOTED_STRING = 'emailAddressQuotedString'; const INVALID_LOCAL_PART = 'emailAddressInvalidLocalPart'; @@ -52,38 +51,13 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be a string", - self::INVALID_FORMAT => "'%value%' is no valid email address in the basic format local-part@hostname", - self::INVALID_HOSTNAME => "'%hostname%' is no valid hostname for email address '%value%'", + self::INVALID_FORMAT => "'%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::INVALID_SEGMENT => "'%hostname%' is not in a routable network segment. The email address '%value%' should not be resolved from public network.", - self::DOT_ATOM => "'%localPart%' can not be matched against dot-atom format", - self::QUOTED_STRING => "'%localPart%' can not be matched against quoted-string format", - self::INVALID_LOCAL_PART => "'%localPart%' is no valid local part for email address '%value%'", - self::LENGTH_EXCEEDED => "'%value%' exceeds the allowed length", - ); - - /** - * @see http://en.wikipedia.org/wiki/IPv4 - * @var array - */ - protected $_invalidIp = array( - '0' => '0.0.0.0/8', - '10' => '10.0.0.0/8', - '127' => '127.0.0.0/8', - '128' => '128.0.0.0/16', - '169' => '169.254.0.0/16', - '172' => '172.16.0.0/12', - '191' => '191.255.0.0/16', - '192' => array( - '192.0.0.0/24', - '192.0.2.0/24', - '192.88.99.0/24', - '192.168.0.0/16' - ), - '198' => '198.18.0.0/15', - '223' => '223.255.255.0/24', - '224' => '224.0.0.0/4', - '240' => '240.0.0.0/4' + 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%'", + self::LENGTH_EXCEEDED => "'%value%' exceeds the allowed length" ); /** @@ -95,128 +69,46 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract ); /** - * @var string - */ - protected $_hostname; - - /** - * @var string - */ - protected $_localPart; - - /** - * Internal options array + * Local object for validating the hostname part of an email address + * + * @var Zend_Validate_Hostname + * @depreciated */ - protected $_options = array( - 'mx' => false, - 'deep' => false, - 'domain' => true, - 'allow' => Zend_Validate_Hostname::ALLOW_DNS, - 'hostname' => null - ); + public $hostnameValidator; /** - * Instantiates hostname validator for local use + * Whether we check for a valid MX record via DNS * - * The following option keys are supported: - * 'hostname' => A hostname validator, see Zend_Validate_Hostname - * 'allow' => Options for the hostname validator, see Zend_Validate_Hostname::ALLOW_* - * 'mx' => If MX check should be enabled, boolean - * 'deep' => If a deep MX check should be done, boolean - * - * @param array|Zend_Config $options OPTIONAL - * @return void + * @var boolean */ - public function __construct($options = array()) - { - if ($options instanceof Zend_Config) { - $options = $options->toArray(); - } else if (!is_array($options)) { - $options = func_get_args(); - $temp['allow'] = array_shift($options); - if (!empty($options)) { - $temp['mx'] = array_shift($options); - } - - if (!empty($options)) { - $temp['hostname'] = array_shift($options); - } - - $options = $temp; - } - - $options += $this->_options; - $this->setOptions($options); - } + protected $_validateMx = false; /** - * Returns all set Options - * - * @return array + * @var string */ - public function getOptions() - { - return $this->_options; - } + protected $_hostname; /** - * Set options for the email validator - * - * @param array $options - * @return Zend_Validate_EmailAddress fluid interface + * @var string */ - public function setOptions(array $options = array()) - { - if (array_key_exists('messages', $options)) { - $this->setMessages($options['messages']); - } - - if (array_key_exists('hostname', $options)) { - if (array_key_exists('allow', $options)) { - $this->setHostnameValidator($options['hostname'], $options['allow']); - } else { - $this->setHostnameValidator($options['hostname']); - } - } - - if (array_key_exists('mx', $options)) { - $this->setValidateMx($options['mx']); - } - - if (array_key_exists('deep', $options)) { - $this->setDeepMxCheck($options['deep']); - } - - if (array_key_exists('domain', $options)) { - $this->setDomainCheck($options['domain']); - } - - return $this; - } + protected $_localPart; /** - * Sets the validation failure message template for a particular key - * Adds the ability to set messages to the attached hostname validator + * 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 string $messageString - * @param string $messageKey OPTIONAL - * @return Zend_Validate_Abstract Provides a fluent interface - * @throws Zend_Validate_Exception + * @param integer $allow OPTIONAL + * @param bool $validateMx OPTIONAL + * @param Zend_Validate_Hostname $hostnameValidator OPTIONAL + * @return void */ - public function setMessage($messageString, $messageKey = null) + public function __construct($allow = Zend_Validate_Hostname::ALLOW_DNS, $validateMx = false, Zend_Validate_Hostname $hostnameValidator = null) { - $messageKeys = $messageKey; - if ($messageKey === null) { - $keys = array_keys($this->_messageTemplates); - $messageKeys = current($keys); - } - - if (!isset($this->_messageTemplates[$messageKeys])) { - $this->_options['hostname']->setMessage($messageString, $messageKey); - } - - $this->_messageTemplates[$messageKeys] = $messageString; - return $this; + $this->setValidateMx($validateMx); + $this->setHostnameValidator($hostnameValidator, $allow); } /** @@ -226,7 +118,7 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract */ public function getHostnameValidator() { - return $this->_options['hostname']; + return $this->hostnameValidator; } /** @@ -236,17 +128,14 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract */ public function setHostnameValidator(Zend_Validate_Hostname $hostnameValidator = null, $allow = Zend_Validate_Hostname::ALLOW_DNS) { - if (!$hostnameValidator) { + if ($hostnameValidator === null) { $hostnameValidator = new Zend_Validate_Hostname($allow); } - - $this->_options['hostname'] = $hostnameValidator; - $this->_options['allow'] = $allow; - return $this; + $this->hostnameValidator = $hostnameValidator; } /** - * Whether MX checking via getmxrr is supported or not + * Whether MX checking via dns_get_mx is supported or not * * This currently only works on UNIX systems * @@ -254,17 +143,7 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract */ public function validateMxSupported() { - return function_exists('getmxrr'); - } - - /** - * Returns the set validateMx option - * - * @return boolean - */ - public function getValidateMx() - { - return $this->_options['mx']; + return function_exists('dns_get_mx'); } /** @@ -272,236 +151,11 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract * * This only applies when DNS hostnames are validated * - * @param boolean $mx Set allowed to true to validate for MX records, and false to not validate them - * @return Zend_Validate_EmailAddress Fluid Interface - */ - public function setValidateMx($mx) - { - if ((bool) $mx && !$this->validateMxSupported()) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('MX checking not available on this system'); - } - - $this->_options['mx'] = (bool) $mx; - return $this; - } - - /** - * Returns the set deepMxCheck option - * - * @return boolean - */ - public function getDeepMxCheck() - { - return $this->_options['deep']; - } - - /** - * Set whether we check MX record should be a deep validation - * - * @param boolean $deep Set deep to true to perform a deep validation process for MX records - * @return Zend_Validate_EmailAddress Fluid Interface + * @param boolean $allowed Set allowed to true to validate for MX records, and false to not validate them */ - public function setDeepMxCheck($deep) + public function setValidateMx($allowed) { - $this->_options['deep'] = (bool) $deep; - return $this; - } - - /** - * Returns the set domainCheck option - * - * @return unknown - */ - public function getDomainCheck() - { - return $this->_options['domain']; - } - - /** - * Sets if the domain should also be checked - * or only the local part of the email address - * - * @param boolean $domain - * @return Zend_Validate_EmailAddress Fluid Interface - */ - public function setDomainCheck($domain = true) - { - $this->_options['domain'] = (boolean) $domain; - return $this; - } - - /** - * Returns if the given host is reserved - * - * @param string $host - * @return boolean - */ - private function _isReserved($host){ - if (!preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $host)) { - $host = gethostbyname($host); - } - - $octet = explode('.',$host); - if ((int)$octet[0] >= 224) { - return true; - } else if (array_key_exists($octet[0], $this->_invalidIp)) { - foreach ((array)$this->_invalidIp[$octet[0]] as $subnetData) { - // we skip the first loop as we already know that octet matches - for ($i = 1; $i < 4; $i++) { - if (strpos($subnetData, $octet[$i]) !== $i * 4) { - break; - } - } - - $host = explode("/", $subnetData); - $binaryHost = ""; - $tmp = explode(".", $host[0]); - for ($i = 0; $i < 4 ; $i++) { - $binaryHost .= str_pad(decbin($tmp[$i]), 8, "0", STR_PAD_LEFT); - } - - $segmentData = array( - 'network' => (int)$this->_toIp(str_pad(substr($binaryHost, 0, $host[1]), 32, 0)), - 'broadcast' => (int)$this->_toIp(str_pad(substr($binaryHost, 0, $host[1]), 32, 1)) - ); - - for ($j = $i; $j < 4; $j++) { - if ((int)$octet[$j] < $segmentData['network'][$j] || - (int)$octet[$j] > $segmentData['broadcast'][$j]) { - return false; - } - } - } - - return true; - } else { - return false; - } - } - - /** - * Converts a binary string to an IP address - * - * @param string $binary - * @return mixed - */ - private function _toIp($binary) - { - $ip = array(); - $tmp = explode(".", chunk_split($binary, 8, ".")); - for ($i = 0; $i < 4 ; $i++) { - $ip[$i] = bindec($tmp[$i]); - } - - return $ip; - } - - /** - * Internal method to validate the local part of the email address - * - * @return boolean - */ - private function _validateLocalPart() - { - // First try to match the local part on the common dot-atom format - $result = false; - - // Dot-atom characters are: 1*atext *("." 1*atext) - // atext: ALPHA / DIGIT / and "!", "#", "$", "%", "&", "'", "*", - // "+", "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~" - $atext = 'a-zA-Z0-9\x21\x23\x24\x25\x26\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b\x7c\x7d\x7e'; - if (preg_match('/^[' . $atext . ']+(\x2e+[' . $atext . ']+)*$/', $this->_localPart)) { - $result = 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)) { - $result = true; - } else { - $this->_error(self::DOT_ATOM); - $this->_error(self::QUOTED_STRING); - $this->_error(self::INVALID_LOCAL_PART); - } - } - - return $result; - } - - /** - * Internal method to validate the servers MX records - * - * @return boolean - */ - private function _validateMXRecords() - { - $mxHosts = array(); - $result = getmxrr($this->_hostname, $mxHosts); - if (!$result) { - $this->_error(self::INVALID_MX_RECORD); - } else if ($this->_options['deep'] && function_exists('checkdnsrr')) { - $validAddress = false; - $reserved = true; - foreach ($mxHosts as $hostname) { - $res = $this->_isReserved($hostname); - if (!$res) { - $reserved = false; - } - - if (!$res - && (checkdnsrr($hostname, "A") - || checkdnsrr($hostname, "AAAA") - || checkdnsrr($hostname, "A6"))) { - $validAddress = true; - break; - } - } - - if (!$validAddress) { - $result = false; - if ($reserved) { - $this->_error(self::INVALID_SEGMENT); - } else { - $this->_error(self::INVALID_MX_RECORD); - } - } - } - - return $result; - } - - /** - * Internal method to validate the hostname part of the email address - * - * @return boolean - */ - private function _validateHostnamePart() - { - $hostname = $this->_options['hostname']->setTranslator($this->getTranslator()) - ->isValid($this->_hostname); - if (!$hostname) { - $this->_error(self::INVALID_HOSTNAME); - - // Get messages and errors from hostnameValidator - foreach ($this->_options['hostname']->getMessages() as $code => $message) { - $this->_messages[$code] = $message; - } - - foreach ($this->_options['hostname']->getErrors() as $error) { - $this->_errors[] = $error; - } - } else if ($this->_options['mx']) { - // MX check on hostname - $hostname = $this->_validateMXRecords(); - } - - return $hostname; + $this->_validateMx = (bool) $allowed; } /** @@ -522,8 +176,9 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract return false; } - $matches = array(); - $length = true; + $matches = array(); + $length = true; + $this->_setValue($value); // Split email address up and disallow '..' @@ -542,19 +197,68 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract } // Match hostname part - if ($this->_options['domain']) { - $hostname = $this->_validateHostnamePart(); + $hostnameResult = $this->hostnameValidator->setTranslator($this->getTranslator()) + ->isValid($this->_hostname); + if (!$hostnameResult) { + $this->_error(self::INVALID_HOSTNAME); + + // Get messages and errors from hostnameValidator + foreach ($this->hostnameValidator->getMessages() as $code => $message) { + $this->_messages[$code] = $message; + } + foreach ($this->hostnameValidator->getErrors() as $error) { + $this->_errors[] = $error; + } + } else if ($this->_validateMx) { + // MX check on hostname via dns_get_record() + if ($this->validateMxSupported()) { + $result = dns_get_mx($this->_hostname, $mxHosts); + if (count($mxHosts) < 1) { + $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'); + } } - $local = $this->_validateLocalPart(); + // First try to match the local part on the common dot-atom format + $localResult = false; - // If both parts valid, return true - if ($local && $length) { - if (($this->_options['domain'] && $hostname) || !$this->_options['domain']) { - return true; + // Dot-atom characters are: 1*atext *("." 1*atext) + // atext: ALPHA / DIGIT / and "!", "#", "$", "%", "&", "'", "*", + // "+", "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~" + $atext = 'a-zA-Z0-9\x21\x23\x24\x25\x26\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b\x7c\x7d\x7e'; + if (preg_match('/^[' . $atext . ']+(\x2e+[' . $atext . ']+)*$/', $this->_localPart)) { + $localResult = true; + } else { + // Try quoted string format + + // Quoted-string characters are: DQUOTE *([FWS] qtext/quoted-pair) [FWS] DQUOTE + // qtext: Non white space controls, and the rest of the US-ASCII characters not + // including "\" or the quote character + $noWsCtl = '\x01-\x08\x0b\x0c\x0e-\x1f\x7f'; + $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); } } - return false; + // If both parts valid, return true + if ($localResult && $hostnameResult && $length) { + return true; + } else { + return false; + } } } diff --git a/libs/Zend/Validate/Exception.php b/libs/Zend/Validate/Exception.php index fd34efe0c1..d6b646f1cd 100644 --- a/libs/Zend/Validate/Exception.php +++ b/libs/Zend/Validate/Exception.php @@ -1,4 +1,5 @@ <?php + /** * Zend Framework * @@ -14,20 +15,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Exception.php 16223 2009-06-21 20:04:53Z thomas $ */ + /** * @see Zend_Exception */ -// require_once 'Zend/Exception.php'; +require_once 'Zend/Exception.php'; + /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 diff --git a/libs/Zend/Validate/File/Count.php b/libs/Zend/Validate/File/Count.php index a4bff7ee8c..f2dfac7413 100644 --- a/libs/Zend/Validate/File/Count.php +++ b/libs/Zend/Validate/File/Count.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Count.php 21326 2010-03-04 20:32:39Z thomas $ + * @version $Id: Count.php 18148 2009-09-16 19:27:43Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * Validator for counting all given files * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_Count extends Zend_Validate_Abstract @@ -37,16 +37,16 @@ class Zend_Validate_File_Count extends Zend_Validate_Abstract /**#@+ * @const string Error constants */ - const TOO_MANY = 'fileCountTooMany'; - const TOO_FEW = 'fileCountTooFew'; + const TOO_MUCH = 'fileCountTooMuch'; + const TOO_LESS = 'fileCountTooLess'; /**#@-*/ /** * @var array Error message templates */ protected $_messageTemplates = array( - self::TOO_MANY => "Too many files, maximum '%max%' are allowed but '%count%' are given", - self::TOO_FEW => "Too few files, minimum '%min%' are expected but '%count%' are given", + self::TOO_MUCH => "Too much files, maximum '%max%' are allowed but '%count%' are given", + self::TOO_LESS => "Too less files, minimum '%min%' are expected but '%count%' are given" ); /** @@ -110,11 +110,13 @@ class Zend_Validate_File_Count extends Zend_Validate_Abstract } elseif (is_string($options) || is_numeric($options)) { $options = array('max' => $options); } elseif (!is_array($options)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception ('Invalid options to validator provided'); } if (1 < func_num_args()) { +// @todo: Preperation for 2.0... needs to be cleared with the dev-team +// trigger_error('Multiple arguments are deprecated in favor of an array of named arguments', E_USER_NOTICE); $options['min'] = func_get_arg(0); $options['max'] = func_get_arg(1); } @@ -152,13 +154,13 @@ class Zend_Validate_File_Count extends Zend_Validate_Abstract } if (!is_string($min) and !is_numeric($min)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception ('Invalid options to validator provided'); } $min = (integer) $min; if (($this->_max !== null) && ($min > $this->_max)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("The minimum must be less than or equal to the maximum file count, but $min >" . " {$this->_max}"); } @@ -191,13 +193,13 @@ class Zend_Validate_File_Count extends Zend_Validate_Abstract } if (!is_string($max) and !is_numeric($max)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception ('Invalid options to validator provided'); } $max = (integer) $max; if (($this->_min !== null) && ($max < $this->_min)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("The maximum must be greater than or equal to the minimum file count, but " . "$max < {$this->_min}"); } @@ -241,25 +243,14 @@ class Zend_Validate_File_Count extends Zend_Validate_Abstract */ public function isValid($value, $file = null) { - if (($file !== null) && !array_key_exists('destination', $file)) { - $file['destination'] = dirname($value); - } - - if (($file !== null) && array_key_exists('tmp_name', $file)) { - $value = $file['destination'] . DIRECTORY_SEPARATOR . $file['name']; - } - - if (($file === null) || !empty($file['tmp_name'])) { - $this->addFile($value); - } - + $this->addFile($value); $this->_count = count($this->_files); if (($this->_max !== null) && ($this->_count > $this->_max)) { - return $this->_throw($file, self::TOO_MANY); + return $this->_throw($file, self::TOO_MUCH); } if (($this->_min !== null) && ($this->_count < $this->_min)) { - return $this->_throw($file, self::TOO_FEW); + return $this->_throw($file, self::TOO_LESS); } return true; diff --git a/libs/Zend/Validate/File/Crc32.php b/libs/Zend/Validate/File/Crc32.php index 31b420585e..fd46d81b6b 100644 --- a/libs/Zend/Validate/File/Crc32.php +++ b/libs/Zend/Validate/File/Crc32.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Crc32.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: Crc32.php 18148 2009-09-16 19:27:43Z thomas $ */ /** * @see Zend_Validate_File_Hash */ -// require_once 'Zend/Validate/File/Hash.php'; +require_once 'Zend/Validate/File/Hash.php'; /** * Validator for the crc32 hash of given files * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_Crc32 extends Zend_Validate_File_Hash @@ -45,9 +45,9 @@ class Zend_Validate_File_Crc32 extends Zend_Validate_File_Hash * @var array Error message templates */ protected $_messageTemplates = array( - self::DOES_NOT_MATCH => "File '%value%' does not match the given crc32 hashes", - self::NOT_DETECTED => "A crc32 hash could not be evaluated for the given file", - self::NOT_FOUND => "File '%value%' could not be found", + self::DOES_NOT_MATCH => "The file '%value%' does not match the given crc32 hashes", + self::NOT_DETECTED => "There was no crc32 hash detected for the given file", + self::NOT_FOUND => "The file '%value%' could not be found" ); /** @@ -70,7 +70,7 @@ class Zend_Validate_File_Crc32 extends Zend_Validate_File_Hash } elseif (is_scalar($options)) { $options = array('hash1' => $options); } elseif (!is_array($options)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception('Invalid options to validator provided'); } @@ -157,7 +157,7 @@ class Zend_Validate_File_Crc32 extends Zend_Validate_File_Hash public function isValid($value, $file = null) { // Is file readable ? - // require_once 'Zend/Loader.php'; + require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_FOUND); } diff --git a/libs/Zend/Validate/File/ExcludeExtension.php b/libs/Zend/Validate/File/ExcludeExtension.php index 94fb27bb6d..74264de98c 100644 --- a/libs/Zend/Validate/File/ExcludeExtension.php +++ b/libs/Zend/Validate/File/ExcludeExtension.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: ExcludeExtension.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: ExcludeExtension.php 16971 2009-07-22 18:05:45Z mikaelkael $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/File/Extension.php'; +require_once 'Zend/Validate/File/Extension.php'; /** * Validator for the excluding file extensions * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_ExcludeExtension extends Zend_Validate_File_Extension @@ -44,8 +44,8 @@ class Zend_Validate_File_ExcludeExtension extends Zend_Validate_File_Extension * @var array Error message templates */ protected $_messageTemplates = array( - self::FALSE_EXTENSION => "File '%value%' has a false extension", - self::NOT_FOUND => "File '%value%' could not be found", + self::FALSE_EXTENSION => "The file '%value%' has a false extension", + self::NOT_FOUND => "The file '%value%' was not found" ); /** @@ -61,7 +61,7 @@ class Zend_Validate_File_ExcludeExtension extends Zend_Validate_File_Extension public function isValid($value, $file = null) { // Is file readable ? - // require_once 'Zend/Loader.php'; + require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_FOUND); } diff --git a/libs/Zend/Validate/File/ExcludeMimeType.php b/libs/Zend/Validate/File/ExcludeMimeType.php index 436caa1f02..4984b79cfb 100644 --- a/libs/Zend/Validate/File/ExcludeMimeType.php +++ b/libs/Zend/Validate/File/ExcludeMimeType.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: ExcludeMimeType.php 21936 2010-04-18 16:23:34Z thomas $ + * @version $Id: ExcludeMimeType.php 18148 2009-09-16 19:27:43Z thomas $ */ /** * @see Zend_Validate_File_MimeType */ -// require_once 'Zend/Validate/File/MimeType.php'; +require_once 'Zend/Validate/File/MimeType.php'; /** * Validator for the mime type of a file * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_ExcludeMimeType extends Zend_Validate_File_MimeType @@ -59,7 +59,7 @@ class Zend_Validate_File_ExcludeMimeType extends Zend_Validate_File_MimeType } // Is file readable ? - // require_once 'Zend/Loader.php'; + require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_READABLE); } @@ -73,7 +73,7 @@ class Zend_Validate_File_ExcludeMimeType extends Zend_Validate_File_MimeType $mime = new finfo($const); } - if (!empty($mime)) { + if ($mime !== false) { $this->_type = $mime->file($value); } unset($mime); diff --git a/libs/Zend/Validate/File/Exists.php b/libs/Zend/Validate/File/Exists.php index 6ecd11f1f0..835b4c2c70 100644 --- a/libs/Zend/Validate/File/Exists.php +++ b/libs/Zend/Validate/File/Exists.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Exists.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: Exists.php 18148 2009-09-16 19:27:43Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * Validator which checks if the file already exists in the directory * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_Exists extends Zend_Validate_Abstract @@ -43,7 +43,7 @@ class Zend_Validate_File_Exists extends Zend_Validate_Abstract * @var array Error message templates */ protected $_messageTemplates = array( - self::DOES_NOT_EXIST => "File '%value%' does not exist", + self::DOES_NOT_EXIST => "The file '%value%' does not exist" ); /** @@ -72,7 +72,7 @@ class Zend_Validate_File_Exists extends Zend_Validate_Abstract } else if (is_string($directory)) { $directory = explode(',', $directory); } else if (!is_array($directory)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception ('Invalid options to validator provided'); } @@ -122,7 +122,7 @@ class Zend_Validate_File_Exists extends Zend_Validate_Abstract if (is_string($directory)) { $directory = explode(',', $directory); } else if (!is_array($directory)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception ('Invalid options to validator provided'); } diff --git a/libs/Zend/Validate/File/Extension.php b/libs/Zend/Validate/File/Extension.php index 8d903e4093..58ab0b21af 100644 --- a/libs/Zend/Validate/File/Extension.php +++ b/libs/Zend/Validate/File/Extension.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Extension.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: Extension.php 18148 2009-09-16 19:27:43Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * Validator for the file extension of a file * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_Extension extends Zend_Validate_Abstract @@ -44,8 +44,8 @@ class Zend_Validate_File_Extension extends Zend_Validate_Abstract * @var array Error message templates */ protected $_messageTemplates = array( - self::FALSE_EXTENSION => "File '%value%' has a false extension", - self::NOT_FOUND => "File '%value%' could not be found", + self::FALSE_EXTENSION => "The file '%value%' has a false extension", + self::NOT_FOUND => "The file '%value%' was not found" ); /** @@ -81,6 +81,8 @@ class Zend_Validate_File_Extension extends Zend_Validate_Abstract } if (1 < func_num_args()) { +// @todo: Preperation for 2.0... needs to be cleared with the dev-team +// trigger_error('Multiple arguments to constructor are deprecated in favor of options array', E_USER_NOTICE); $case = func_get_arg(1); $this->setCase($case); } @@ -187,7 +189,7 @@ class Zend_Validate_File_Extension extends Zend_Validate_Abstract public function isValid($value, $file = null) { // Is file readable ? - // require_once 'Zend/Loader.php'; + require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_FOUND); } diff --git a/libs/Zend/Validate/File/FilesSize.php b/libs/Zend/Validate/File/FilesSize.php index ca20ad50af..167304b771 100644 --- a/libs/Zend/Validate/File/FilesSize.php +++ b/libs/Zend/Validate/File/FilesSize.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: FilesSize.php 20455 2010-01-20 22:54:18Z thomas $ + * @version $Id: FilesSize.php 18148 2009-09-16 19:27:43Z thomas $ */ /** * @see Zend_Validate_File_Size */ -// require_once 'Zend/Validate/File/Size.php'; +require_once 'Zend/Validate/File/Size.php'; /** * Validator for the size of all files which will be validated in sum * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size @@ -47,7 +47,7 @@ class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size protected $_messageTemplates = array( self::TOO_BIG => "All files in sum should have a maximum size of '%max%' but '%size%' were detected", self::TOO_SMALL => "All files in sum should have a minimum size of '%min%' but '%size%' were detected", - self::NOT_READABLE => "One or more files can not be read", + self::NOT_READABLE => "One or more files can not be read" ); /** @@ -76,11 +76,14 @@ class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size } elseif (is_scalar($options)) { $options = array('max' => $options); } elseif (!is_array($options)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception('Invalid options to validator provided'); } if (1 < func_num_args()) { +// @todo: Preperation for 2.0... needs to be cleared with the dev-team +// trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE); + $argv = func_get_args(); array_shift($argv); $options['max'] = array_shift($argv); @@ -104,7 +107,7 @@ class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size */ public function isValid($value, $file = null) { - // require_once 'Zend/Loader.php'; + require_once 'Zend/Loader.php'; if (is_string($value)) { $value = array($value); } @@ -128,14 +131,12 @@ class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size // limited to 2GB files $size += @filesize($files); - $this->_size = $size; + $this->_setSize($size); if (($max !== null) && ($max < $size)) { if ($this->useByteString()) { - $this->_max = $this->_toByteString($max); - $this->_size = $this->_toByteString($size); + $this->setMax($this->_toByteString($max)); $this->_throw($file, self::TOO_BIG); - $this->_max = $max; - $this->_size = $size; + $this->setMax($max); } else { $this->_throw($file, self::TOO_BIG); } @@ -145,11 +146,9 @@ class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size // Check that aggregate files are >= minimum size if (($min !== null) && ($size < $min)) { if ($this->useByteString()) { - $this->_min = $this->_toByteString($min); - $this->_size = $this->_toByteString($size); + $this->setMin($this->_toByteString($min)); $this->_throw($file, self::TOO_SMALL); - $this->_min = $min; - $this->_size = $size; + $this->setMin($min); } else { $this->_throw($file, self::TOO_SMALL); } diff --git a/libs/Zend/Validate/File/Hash.php b/libs/Zend/Validate/File/Hash.php index 6ade30cf41..d2e8c2c645 100644 --- a/libs/Zend/Validate/File/Hash.php +++ b/libs/Zend/Validate/File/Hash.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Hash.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: Hash.php 18148 2009-09-16 19:27:43Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * Validator for the hash of given files * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_Hash extends Zend_Validate_Abstract @@ -45,9 +45,9 @@ class Zend_Validate_File_Hash extends Zend_Validate_Abstract * @var array Error message templates */ protected $_messageTemplates = array( - self::DOES_NOT_MATCH => "File '%value%' does not match the given hashes", - self::NOT_DETECTED => "A hash could not be evaluated for the given file", - self::NOT_FOUND => "File '%value%' could not be found" + self::DOES_NOT_MATCH => "The file '%value%' does not match the given hashes", + self::NOT_DETECTED => "There was no hash detected for the given file", + self::NOT_FOUND => "The file '%value%' could not be found" ); /** @@ -70,11 +70,13 @@ class Zend_Validate_File_Hash extends Zend_Validate_Abstract } elseif (is_scalar($options)) { $options = array('hash1' => $options); } elseif (!is_array($options)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception('Invalid options to validator provided'); } if (1 < func_num_args()) { +// @todo: Preperation for 2.0... needs to be cleared with the dev-team +// trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE); $options['algorithm'] = func_get_arg(1); } @@ -116,7 +118,7 @@ class Zend_Validate_File_Hash extends Zend_Validate_Abstract if (is_string($options)) { $options = array($options); } else if (!is_array($options)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("False parameter given"); } @@ -129,7 +131,7 @@ class Zend_Validate_File_Hash extends Zend_Validate_Abstract } if (!in_array($algorithm, $known)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("Unknown algorithm '{$algorithm}'"); } @@ -152,7 +154,7 @@ class Zend_Validate_File_Hash extends Zend_Validate_Abstract public function isValid($value, $file = null) { // Is file readable ? - // require_once 'Zend/Loader.php'; + require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_FOUND); } diff --git a/libs/Zend/Validate/File/ImageSize.php b/libs/Zend/Validate/File/ImageSize.php index 54c1457500..c01ec97341 100644 --- a/libs/Zend/Validate/File/ImageSize.php +++ b/libs/Zend/Validate/File/ImageSize.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: ImageSize.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: ImageSize.php 18148 2009-09-16 19:27:43Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * Validator for the image size of a image file * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_ImageSize extends Zend_Validate_Abstract @@ -53,7 +53,7 @@ class Zend_Validate_File_ImageSize extends Zend_Validate_Abstract self::HEIGHT_TOO_BIG => "Maximum allowed height for image '%value%' should be '%maxheight%' but '%height%' detected", self::HEIGHT_TOO_SMALL => "Minimum expected height for image '%value%' should be '%minheight%' but '%height%' detected", self::NOT_DETECTED => "The size of image '%value%' could not be detected", - self::NOT_READABLE => "File '%value%' can not be read", + self::NOT_READABLE => "The image '%value%' can not be read" ); /** @@ -127,6 +127,8 @@ class Zend_Validate_File_ImageSize extends Zend_Validate_Abstract if ($options instanceof Zend_Config) { $options = $options->toArray(); } elseif (1 < func_num_args()) { +// @todo: Preperation for 2.0... needs to be cleared with the dev-team +// trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE); if (!is_array($options)) { $options = array('minwidth' => $options); } @@ -140,7 +142,7 @@ class Zend_Validate_File_ImageSize extends Zend_Validate_Abstract } } } else if (!is_array($options)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception ('Invalid options to validator provided'); } @@ -205,7 +207,7 @@ class Zend_Validate_File_ImageSize extends Zend_Validate_Abstract { if (isset($options['minwidth'])) { if (($this->_maxwidth !== null) and ($options['minwidth'] > $this->_maxwidth)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("The minimum image width must be less than or equal to the " . " maximum image width, but {$options['minwidth']} > {$this->_maxwidth}"); } @@ -213,7 +215,7 @@ class Zend_Validate_File_ImageSize extends Zend_Validate_Abstract if (isset($options['maxheight'])) { if (($this->_maxheight !== null) and ($options['minheight'] > $this->_maxheight)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("The minimum image height must be less than or equal to the " . " maximum image height, but {$options['minheight']} > {$this->_maxheight}"); } @@ -242,7 +244,7 @@ class Zend_Validate_File_ImageSize extends Zend_Validate_Abstract { if (isset($options['maxwidth'])) { if (($this->_minwidth !== null) and ($options['maxwidth'] < $this->_minwidth)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("The maximum image width must be greater than or equal to the " . "minimum image width, but {$options['maxwidth']} < {$this->_minwidth}"); } @@ -250,7 +252,7 @@ class Zend_Validate_File_ImageSize extends Zend_Validate_Abstract if (isset($options['maxheight'])) { if (($this->_minheight !== null) and ($options['maxheight'] < $this->_minheight)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("The maximum image height must be greater than or equal to the " . "minimum image height, but {$options['maxheight']} < {$this->_minwidth}"); } @@ -308,7 +310,7 @@ class Zend_Validate_File_ImageSize extends Zend_Validate_Abstract public function isValid($value, $file = null) { // Is file readable ? - // require_once 'Zend/Loader.php'; + require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_READABLE); } diff --git a/libs/Zend/Validate/File/IsCompressed.php b/libs/Zend/Validate/File/IsCompressed.php index dc0d99abb5..3254d57341 100644 --- a/libs/Zend/Validate/File/IsCompressed.php +++ b/libs/Zend/Validate/File/IsCompressed.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: IsCompressed.php 21138 2010-02-22 22:37:11Z thomas $ + * @version $Id: IsCompressed.php 18148 2009-09-16 19:27:43Z thomas $ */ /** * @see Zend_Validate_File_MimeType */ -// require_once 'Zend/Validate/File/MimeType.php'; +require_once 'Zend/Validate/File/MimeType.php'; /** * Validator which checks if the file already exists in the directory * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_IsCompressed extends Zend_Validate_File_MimeType @@ -45,9 +45,9 @@ class Zend_Validate_File_IsCompressed extends Zend_Validate_File_MimeType * @var array Error message templates */ protected $_messageTemplates = array( - self::FALSE_TYPE => "File '%value%' is not compressed, '%type%' detected", - self::NOT_DETECTED => "The mimetype of file '%value%' could not been detected", - self::NOT_READABLE => "File '%value%' can not be read", + self::FALSE_TYPE => "The file '%value%' is not compressed, '%type%' detected", + self::NOT_DETECTED => "The mimetype of file '%value%' has not been detected", + self::NOT_READABLE => "The file '%value%' can not be read" ); /** @@ -60,90 +60,27 @@ class Zend_Validate_File_IsCompressed extends Zend_Validate_File_MimeType { if ($mimetype instanceof Zend_Config) { $mimetype = $mimetype->toArray(); + } else if (empty($mimetype)) { + $mimetype = array( + 'application/x-tar', + 'application/x-cpio', + 'application/x-debian-package', + 'application/x-archive', + 'application/x-arc', + 'application/x-arj', + 'application/x-lharc', + 'application/x-lha', + 'application/x-rar', + 'application/zip', + 'application/zoo', + 'application/x-eet', + 'application/x-java-pack200', + 'application/x-compress', + 'application/x-gzip', + 'application/x-bzip2' + ); } - $temp = array(); - // http://de.wikipedia.org/wiki/Liste_von_Dateiendungen - $default = array( - 'application/arj', - 'application/gnutar', - 'application/lha', - 'application/lzx', - 'application/vnd.ms-cab-compressed', - 'application/x-ace-compressed', - 'application/x-arc', - 'application/x-archive', - 'application/x-arj', - 'application/x-bzip', - 'application/x-bzip2', - 'application/x-cab-compressed', - 'application/x-compress', - 'application/x-compressed', - 'application/x-cpio', - 'application/x-debian-package', - 'application/x-eet', - 'application/x-gzip', - 'application/x-java-pack200', - 'application/x-lha', - 'application/x-lharc', - 'application/x-lzh', - 'application/x-lzma', - 'application/x-lzx', - 'application/x-rar', - 'application/x-sit', - 'application/x-stuffit', - 'application/x-tar', - 'application/zip', - 'application/zoo', - 'multipart/x-gzip', - ); - - if (is_array($mimetype)) { - $temp = $mimetype; - if (array_key_exists('magicfile', $temp)) { - unset($temp['magicfile']); - } - - if (array_key_exists('headerCheck', $temp)) { - unset($temp['headerCheck']); - } - - if (empty($temp)) { - $mimetype += $default; - } - } - - if (empty($mimetype)) { - $mimetype = $default; - } - - parent::__construct($mimetype); - } - - /** - * Throws an error of the given type - * Duplicates parent method due to OOP Problem with late static binding in PHP 5.2 - * - * @param string $file - * @param string $errorType - * @return false - */ - protected function _throw($file, $errorType) - { - $this->_value = $file['name']; - switch($errorType) { - case Zend_Validate_File_MimeType::FALSE_TYPE : - $errorType = self::FALSE_TYPE; - break; - case Zend_Validate_File_MimeType::NOT_DETECTED : - $errorType = self::NOT_DETECTED; - break; - case Zend_Validate_File_MimeType::NOT_READABLE : - $errorType = self::NOT_READABLE; - break; - } - - $this->_error($errorType); - return false; + $this->setMimeType($mimetype); } } diff --git a/libs/Zend/Validate/File/IsImage.php b/libs/Zend/Validate/File/IsImage.php index d602ebe763..3904af1f90 100644 --- a/libs/Zend/Validate/File/IsImage.php +++ b/libs/Zend/Validate/File/IsImage.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: IsImage.php 21138 2010-02-22 22:37:11Z thomas $ + * @version $Id: IsImage.php 18148 2009-09-16 19:27:43Z thomas $ */ /** * @see Zend_Validate_File_MimeType */ -// require_once 'Zend/Validate/File/MimeType.php'; +require_once 'Zend/Validate/File/MimeType.php'; /** * Validator which checks if the file already exists in the directory * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_IsImage extends Zend_Validate_File_MimeType @@ -45,9 +45,9 @@ class Zend_Validate_File_IsImage extends Zend_Validate_File_MimeType * @var array Error message templates */ protected $_messageTemplates = array( - self::FALSE_TYPE => "File '%value%' is no image, '%type%' detected", - self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected", - self::NOT_READABLE => "File '%value%' can not be read", + self::FALSE_TYPE => "The file '%value%' is no image, '%type%' detected", + self::NOT_DETECTED => "The mimetype of file '%value%' has not been detected", + self::NOT_READABLE => "The file '%value%' can not be read" ); /** @@ -60,114 +60,31 @@ class Zend_Validate_File_IsImage extends Zend_Validate_File_MimeType { if ($mimetype instanceof Zend_Config) { $mimetype = $mimetype->toArray(); + } else if (empty($mimetype)) { + $mimetype = array( + 'image/x-quicktime', + 'image/jp2', + 'image/x-xpmi', + 'image/x-portable-bitmap', + 'image/x-portable-greymap', + 'image/x-portable-pixmap', + 'image/x-niff', + 'image/tiff', + 'image/png', + 'image/x-unknown', + 'image/gif', + 'image/x-ms-bmp', + 'application/dicom', + 'image/vnd.adobe.photoshop', + 'image/vnd.djvu', + 'image/x-cpi', + 'image/jpeg', + 'image/x-ico', + 'image/x-coreldraw', + 'image/svg+xml' + ); } - $temp = array(); - // http://de.wikipedia.org/wiki/Liste_von_Dateiendungen - // http://www.iana.org/assignments/media-types/image/ - $default = array( - 'application/cdf', - 'application/dicom', - 'application/fractals', - 'application/postscript', - 'application/vnd.hp-hpgl', - 'application/vnd.oasis.opendocument.graphics', - 'application/x-cdf', - 'application/x-cmu-raster', - 'application/x-ima', - 'application/x-inventor', - 'application/x-koan', - 'application/x-portable-anymap', - 'application/x-world-x-3dmf', - 'image/bmp', - 'image/c', - 'image/cgm', - 'image/fif', - 'image/gif', - 'image/jpeg', - 'image/jpm', - 'image/jpx', - 'image/jp2', - 'image/naplps', - 'image/pjpeg', - 'image/png', - 'image/svg', - 'image/svg+xml', - 'image/tiff', - 'image/vnd.adobe.photoshop', - 'image/vnd.djvu', - 'image/vnd.fpx', - 'image/vnd.net-fpx', - 'image/x-cmu-raster', - 'image/x-cmx', - 'image/x-coreldraw', - 'image/x-cpi', - 'image/x-emf', - 'image/x-ico', - 'image/x-icon', - 'image/x-jg', - 'image/x-ms-bmp', - 'image/x-niff', - 'image/x-pict', - 'image/x-pcx', - 'image/x-portable-anymap', - 'image/x-portable-bitmap', - 'image/x-portable-greymap', - 'image/x-portable-pixmap', - 'image/x-quicktime', - 'image/x-rgb', - 'image/x-tiff', - 'image/x-unknown', - 'image/x-windows-bmp', - 'image/x-xpmi', - ); - - if (is_array($mimetype)) { - $temp = $mimetype; - if (array_key_exists('magicfile', $temp)) { - unset($temp['magicfile']); - } - - if (array_key_exists('headerCheck', $temp)) { - unset($temp['headerCheck']); - } - - if (empty($temp)) { - $mimetype += $default; - } - } - - if (empty($mimetype)) { - $mimetype = $default; - } - - parent::__construct($mimetype); - } - - /** - * Throws an error of the given type - * Duplicates parent method due to OOP Problem with late static binding in PHP 5.2 - * - * @param string $file - * @param string $errorType - * @return false - */ - protected function _throw($file, $errorType) - { - $this->_value = $file['name']; - switch($errorType) { - case Zend_Validate_File_MimeType::FALSE_TYPE : - $errorType = self::FALSE_TYPE; - break; - case Zend_Validate_File_MimeType::NOT_DETECTED : - $errorType = self::NOT_DETECTED; - break; - case Zend_Validate_File_MimeType::NOT_READABLE : - $errorType = self::NOT_READABLE; - break; - } - - $this->_error($errorType); - return false; + $this->setMimeType($mimetype); } } diff --git a/libs/Zend/Validate/File/Md5.php b/libs/Zend/Validate/File/Md5.php index e76df71917..cfbd83fb53 100644 --- a/libs/Zend/Validate/File/Md5.php +++ b/libs/Zend/Validate/File/Md5.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Md5.php 20442 2010-01-20 15:15:40Z matthew $ + * @version $Id: Md5.php 16971 2009-07-22 18:05:45Z mikaelkael $ */ /** * @see Zend_Validate_File_Hash */ -// require_once 'Zend/Validate/File/Hash.php'; +require_once 'Zend/Validate/File/Hash.php'; /** * Validator for the md5 hash of given files * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_Md5 extends Zend_Validate_File_Hash @@ -45,9 +45,9 @@ class Zend_Validate_File_Md5 extends Zend_Validate_File_Hash * @var array Error message templates */ protected $_messageTemplates = array( - self::DOES_NOT_MATCH => "File '%value%' does not match the given md5 hashes", - self::NOT_DETECTED => "A md5 hash could not be evaluated for the given file", - self::NOT_FOUND => "File '%value%' could not be found", + self::DOES_NOT_MATCH => "The file '%value%' does not match the given md5 hashes", + self::NOT_DETECTED => "There was no md5 hash detected for the given file", + self::NOT_FOUND => "The file '%value%' could not be found" ); /** @@ -72,7 +72,7 @@ class Zend_Validate_File_Md5 extends Zend_Validate_File_Hash } elseif (is_scalar($options)) { $options = array('hash1' => $options); } elseif (!is_array($options)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception('Invalid options to validator provided'); } @@ -123,7 +123,7 @@ class Zend_Validate_File_Md5 extends Zend_Validate_File_Hash * Adds the md5 hash for one or multiple files * * @param string|array $options - * @param string $algorithm (Deprecated) Algorithm to use, fixed to md5 + * @param string $algorithm (Depreciated) Algorithm to use, fixed to md5 * @return Zend_Validate_File_Hash Provides a fluent interface */ public function addHash($options) @@ -161,7 +161,7 @@ class Zend_Validate_File_Md5 extends Zend_Validate_File_Hash public function isValid($value, $file = null) { // Is file readable ? - // require_once 'Zend/Loader.php'; + require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_FOUND); } diff --git a/libs/Zend/Validate/File/MimeType.php b/libs/Zend/Validate/File/MimeType.php index a31a7d35a3..2bf372c4fc 100644 --- a/libs/Zend/Validate/File/MimeType.php +++ b/libs/Zend/Validate/File/MimeType.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: MimeType.php 21936 2010-04-18 16:23:34Z thomas $ + * @version $Id: MimeType.php 18513 2009-10-12 16:17:35Z matthew $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * Validator for the mime type of a file * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract @@ -46,9 +46,9 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract * @var array Error message templates */ protected $_messageTemplates = array( - self::FALSE_TYPE => "File '%value%' has a false mimetype of '%type%'", - self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected", - self::NOT_READABLE => "File '%value%' can not be read", + self::FALSE_TYPE => "The file '%value%' has a false mimetype of '%type%'", + self::NOT_DETECTED => "The mimetype of file '%value%' could not been detected", + self::NOT_READABLE => "The file '%value%' can not be read" ); /** @@ -80,13 +80,6 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract protected $_magicfile; /** - * Finfo object to use - * - * @var resource - */ - protected $_finfo; - - /** * If no $_ENV['MAGIC'] is set, try and autodiscover it based on common locations * @var array */ @@ -124,18 +117,16 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract } elseif (is_string($mimetype)) { $mimetype = explode(',', $mimetype); } elseif (!is_array($mimetype)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("Invalid options to validator provided"); } if (isset($mimetype['magicfile'])) { $this->setMagicFile($mimetype['magicfile']); - unset($mimetype['magicfile']); } if (isset($mimetype['headerCheck'])) { - $this->enableHeaderCheck($mimetype['headerCheck']); - unset($mimetype['headerCheck']); + $this->enableHeaderCheck(true); } $this->setMimeType($mimetype); @@ -148,62 +139,33 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract */ public function getMagicFile() { - if (null === $this->_magicfile) { - if (!empty($_ENV['MAGIC'])) { - $this->setMagicFile($_ENV['MAGIC']); - } elseif (!(@ini_get("safe_mode") == 'On' || @ini_get("safe_mode") === 1)) { - // require_once 'Zend/Validate/Exception.php'; - foreach ($this->_magicFiles as $file) { - // supressing errors which are thrown due to openbase_dir restrictions - try { - $this->setMagicFile($file); - if ($this->_magicfile !== null) { - break; - } - } catch (Zend_Validate_Exception $e) { - // Intentionally, catch and fall through - } + if (null === $this->_magicfile && empty($_ENV['MAGIC'])) { + foreach ($this->_magicFiles as $file) { + if (file_exists($file)) { + $this->setMagicFile($file); + break; } } - - if ($this->_magicfile === null) { - $this->_magicfile = false; - } } - return $this->_magicfile; } /** * Sets the magicfile to use * if null, the MAGIC constant from php is used - * if the MAGIC file is errorous, no file will be set * * @param string $file - * @throws Zend_Validate_Exception When finfo can not read the magicfile * @return Zend_Validate_File_MimeType Provides fluid interface */ public function setMagicFile($file) { if (empty($file)) { $this->_magicfile = null; - } else if (!(class_exists('finfo', false))) { - $this->_magicfile = null; - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('Magicfile can not be set. There is no finfo extension installed'); } else if (!is_readable($file)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception('The given magicfile can not be read'); } else { - $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME; - $this->_finfo = @finfo_open($const, $file); - if (empty($this->_finfo)) { - $this->_finfo = null; - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('The given magicfile is not accepted by finfo'); - } else { - $this->_magicfile = $file; - } + $this->_magicfile = (string) $file; } return $this; @@ -275,7 +237,7 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract if (is_string($mimetype)) { $mimetype = explode(',', $mimetype); } elseif (!is_array($mimetype)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("Invalid options to validator provided"); } @@ -324,7 +286,7 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract } // Is file readable ? - // require_once 'Zend/Loader.php'; + require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_READABLE); } @@ -332,27 +294,24 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract $mimefile = $this->getMagicFile(); if (class_exists('finfo', false)) { $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME; - if (!empty($mimefile) && empty($this->_finfo)) { - $this->_finfo = @finfo_open($const, $mimefile); - } - - if (empty($this->_finfo)) { - $this->_finfo = @finfo_open($const); + if (!empty($mimefile)) { + $mime = new finfo($const, $mimefile); + } else { + $mime = new finfo($const); } - $this->_type = null; - if (!empty($this->_finfo)) { - $this->_type = finfo_file($this->_finfo, $value); + if ($mime !== false) { + $this->_type = $mime->file($value); } + unset($mime); } - if (empty($this->_type) && - (function_exists('mime_content_type') && ini_get('mime_magic.magicfile'))) { + if (empty($this->_type)) { + if (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) { $this->_type = mime_content_type($value); - } - - if (empty($this->_type) && $this->_headerCheck) { - $this->_type = $file['type']; + } elseif ($this->_headerCheck) { + $this->_type = $file['type']; + } } if (empty($this->_type)) { @@ -366,7 +325,6 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract $types = explode('/', $this->_type); $types = array_merge($types, explode('-', $this->_type)); - $types = array_merge($types, explode(';', $this->_type)); foreach($mimetype as $mime) { if (in_array($mime, $types)) { return true; diff --git a/libs/Zend/Validate/File/NotExists.php b/libs/Zend/Validate/File/NotExists.php index a5afe94686..0cc3c87ac9 100644 --- a/libs/Zend/Validate/File/NotExists.php +++ b/libs/Zend/Validate/File/NotExists.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: NotExists.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: NotExists.php 16971 2009-07-22 18:05:45Z mikaelkael $ */ /** * @see Zend_Validate_File_Exists */ -// require_once 'Zend/Validate/File/Exists.php'; +require_once 'Zend/Validate/File/Exists.php'; /** * Validator which checks if the destination file does not exist * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_NotExists extends Zend_Validate_File_Exists @@ -43,7 +43,7 @@ class Zend_Validate_File_NotExists extends Zend_Validate_File_Exists * @var array Error message templates */ protected $_messageTemplates = array( - self::DOES_EXIST => "File '%value%' exists", + self::DOES_EXIST => "The file '%value%' does exist" ); /** diff --git a/libs/Zend/Validate/File/Sha1.php b/libs/Zend/Validate/File/Sha1.php index 1b5f8ee622..9dd4418d71 100644 --- a/libs/Zend/Validate/File/Sha1.php +++ b/libs/Zend/Validate/File/Sha1.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Sha1.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: Sha1.php 16971 2009-07-22 18:05:45Z mikaelkael $ */ /** * @see Zend_Validate_File_Hash */ -// require_once 'Zend/Validate/File/Hash.php'; +require_once 'Zend/Validate/File/Hash.php'; /** * Validator for the sha1 hash of given files * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_Sha1 extends Zend_Validate_File_Hash @@ -45,9 +45,9 @@ class Zend_Validate_File_Sha1 extends Zend_Validate_File_Hash * @var array Error message templates */ protected $_messageTemplates = array( - self::DOES_NOT_MATCH => "File '%value%' does not match the given sha1 hashes", - self::NOT_DETECTED => "A sha1 hash could not be evaluated for the given file", - self::NOT_FOUND => "File '%value%' could not be found", + self::DOES_NOT_MATCH => "The file '%value%' does not match the given sha1 hashes", + self::NOT_DETECTED => "There was no sha1 hash detected for the given file", + self::NOT_FOUND => "The file '%value%' could not be found" ); /** @@ -72,7 +72,7 @@ class Zend_Validate_File_Sha1 extends Zend_Validate_File_Hash } elseif (is_scalar($options)) { $options = array('hash1' => $options); } elseif (!is_array($options)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception('Invalid options to validator provided'); } @@ -159,7 +159,7 @@ class Zend_Validate_File_Sha1 extends Zend_Validate_File_Hash public function isValid($value, $file = null) { // Is file readable ? - // require_once 'Zend/Loader.php'; + require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_FOUND); } diff --git a/libs/Zend/Validate/File/Size.php b/libs/Zend/Validate/File/Size.php index a3431cfae1..4c41178966 100644 --- a/libs/Zend/Validate/File/Size.php +++ b/libs/Zend/Validate/File/Size.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Size.php 20455 2010-01-20 22:54:18Z thomas $ + * @version $Id: Size.php 18148 2009-09-16 19:27:43Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * Validator for the maximum size of a file up to a max of 2GB * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_Size extends Zend_Validate_Abstract @@ -48,7 +48,7 @@ class Zend_Validate_File_Size extends Zend_Validate_Abstract protected $_messageTemplates = array( self::TOO_BIG => "Maximum allowed size for file '%value%' is '%max%' but '%size%' detected", self::TOO_SMALL => "Minimum expected size for file '%value%' is '%min%' but '%size%' detected", - self::NOT_FOUND => "File '%value%' could not be found", + self::NOT_FOUND => "The file '%value%' could not be found" ); /** @@ -107,11 +107,13 @@ class Zend_Validate_File_Size extends Zend_Validate_Abstract } elseif (is_string($options) || is_numeric($options)) { $options = array('max' => $options); } elseif (!is_array($options)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception ('Invalid options to validator provided'); } if (1 < func_num_args()) { +// @todo: Preperation for 2.0... needs to be cleared with the dev-team +// trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE); $argv = func_get_args(); array_shift($argv); $options['max'] = array_shift($argv); @@ -181,14 +183,14 @@ class Zend_Validate_File_Size extends Zend_Validate_Abstract public function setMin($min) { if (!is_string($min) and !is_numeric($min)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception ('Invalid options to validator provided'); } $min = (integer) $this->_fromByteString($min); $max = $this->getMax(true); if (($max !== null) && ($min > $max)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("The minimum must be less than or equal to the maximum filesize, but $min >" . " $max"); } @@ -223,14 +225,14 @@ class Zend_Validate_File_Size extends Zend_Validate_Abstract public function setMax($max) { if (!is_string($max) && !is_numeric($max)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception ('Invalid options to validator provided'); } $max = (integer) $this->_fromByteString($max); $min = $this->getMin(true); if (($min !== null) && ($max < $min)) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("The maximum must be greater than or equal to the minimum filesize, but " . "$max < $min"); } @@ -274,14 +276,13 @@ class Zend_Validate_File_Size extends Zend_Validate_Abstract public function isValid($value, $file = null) { // Is file readable ? - // require_once 'Zend/Loader.php'; + require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_FOUND); } // limited to 4GB files - $size = sprintf("%u", @filesize($value)); - $this->_size = $size; + $size = sprintf("%u", @filesize($value)); // Check to see if it's smaller than min size $min = $this->getMin(true); diff --git a/libs/Zend/Validate/File/Upload.php b/libs/Zend/Validate/File/Upload.php index 9a12f301d1..fd1bdfe754 100644 --- a/libs/Zend/Validate/File/Upload.php +++ b/libs/Zend/Validate/File/Upload.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Upload.php 20431 2010-01-19 21:36:05Z thomas $ + * @version $Id: Upload.php 18148 2009-09-16 19:27:43Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * Validator for the maximum size of a file up to a max of 2GB * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_Upload extends Zend_Validate_Abstract @@ -53,16 +53,16 @@ class Zend_Validate_File_Upload extends Zend_Validate_Abstract * @var array Error message templates */ protected $_messageTemplates = array( - self::INI_SIZE => "File '%value%' exceeds the defined ini size", - self::FORM_SIZE => "File '%value%' exceeds the defined form size", - self::PARTIAL => "File '%value%' was only partially uploaded", - self::NO_FILE => "File '%value%' was not uploaded", - self::NO_TMP_DIR => "No temporary directory was found for file '%value%'", - self::CANT_WRITE => "File '%value%' can't be written", - self::EXTENSION => "A PHP extension returned an error while uploading the file '%value%'", - self::ATTACK => "File '%value%' was illegally uploaded. This could be a possible attack", - self::FILE_NOT_FOUND => "File '%value%' was not found", - self::UNKNOWN => "Unknown error while uploading file '%value%'" + self::INI_SIZE => "The file '%value%' exceeds the defined ini size", + self::FORM_SIZE => "The file '%value%' exceeds the defined form size", + self::PARTIAL => "The file '%value%' was only partially uploaded", + self::NO_FILE => "The file '%value%' was not uploaded", + self::NO_TMP_DIR => "No temporary directory was found for the file '%value%'", + self::CANT_WRITE => "The file '%value%' can't be written", + self::EXTENSION => "The extension returned an error while uploading the file '%value%'", + self::ATTACK => "The file '%value%' was illegal uploaded, possible attack", + self::FILE_NOT_FOUND => "The file '%value%' was not found", + self::UNKNOWN => "Unknown error while uploading the file '%value%'" ); /** @@ -112,7 +112,7 @@ class Zend_Validate_File_Upload extends Zend_Validate_Abstract } if (count($return) === 0) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("The file '$file' was not found"); } diff --git a/libs/Zend/Validate/File/WordCount.php b/libs/Zend/Validate/File/WordCount.php index e69bf1db79..b5249532d3 100644 --- a/libs/Zend/Validate/File/WordCount.php +++ b/libs/Zend/Validate/File/WordCount.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: WordCount.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: WordCount.php 16971 2009-07-22 18:05:45Z mikaelkael $ */ /** * @see Zend_Validate_File_Count */ -// require_once 'Zend/Validate/File/Count.php'; +require_once 'Zend/Validate/File/Count.php'; /** * Validator for counting all words in a file * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_File_WordCount extends Zend_Validate_File_Count @@ -48,7 +48,7 @@ class Zend_Validate_File_WordCount extends Zend_Validate_File_Count protected $_messageTemplates = array( self::TOO_MUCH => "Too much words, maximum '%max%' are allowed but '%count%' were counted", self::TOO_LESS => "Too less words, minimum '%min%' are expected but '%count%' were counted", - self::NOT_FOUND => "File '%value%' could not be found", + self::NOT_FOUND => "The file '%value%' could not be found" ); /** @@ -64,7 +64,7 @@ class Zend_Validate_File_WordCount extends Zend_Validate_File_Count public function isValid($value, $file = null) { // Is file readable ? - // require_once 'Zend/Loader.php'; + require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_FOUND); } diff --git a/libs/Zend/Validate/Float.php b/libs/Zend/Validate/Float.php index 37755a8ab7..bfa5e62c14 100644 --- a/libs/Zend/Validate/Float.php +++ b/libs/Zend/Validate/Float.php @@ -14,25 +14,25 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Float.php 21664 2010-03-27 21:39:38Z thomas $ + * @version $Id: Float.php 17470 2009-08-08 22:27:09Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * @see Zend_Locale_Format */ -// require_once 'Zend/Locale/Format.php'; +require_once 'Zend/Locale/Format.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 @@ -45,7 +45,7 @@ class Zend_Validate_Float extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be float, string, or integer", - self::NOT_FLOAT => "'%value%' does not appear to be a float", + self::NOT_FLOAT => "'%value%' does not appear to be a float" ); protected $_locale; @@ -53,30 +53,13 @@ class Zend_Validate_Float extends Zend_Validate_Abstract /** * Constructor for the float validator * - * @param string|Zend_Config|Zend_Locale $locale + * @param string|Zend_Locale $locale */ public function __construct($locale = null) { - if ($locale instanceof Zend_Config) { - $locale = $locale->toArray(); - } - - if (is_array($locale)) { - if (array_key_exists('locale', $locale)) { - $locale = $locale['locale']; - } else { - $locale = null; - } + if ($locale !== null) { + $this->setLocale($locale); } - - if (empty($locale)) { - // require_once 'Zend/Registry.php'; - if (Zend_Registry::isRegistered('Zend_Locale')) { - $locale = Zend_Registry::get('Zend_Locale'); - } - } - - $this->setLocale($locale); } /** @@ -94,7 +77,7 @@ class Zend_Validate_Float extends Zend_Validate_Abstract */ public function setLocale($locale = null) { - // require_once 'Zend/Locale.php'; + require_once 'Zend/Locale.php'; $this->_locale = Zend_Locale::findLocale($locale); return $this; } @@ -114,19 +97,28 @@ class Zend_Validate_Float extends Zend_Validate_Abstract return false; } - if (is_float($value)) { - return true; - } - $this->_setValue($value); - try { - if (!Zend_Locale_Format::isFloat($value, array('locale' => $this->_locale))) { + if ($this->_locale === null) { + $locale = localeconv(); + $valueFiltered = str_replace($locale['thousands_sep'], '', (string) $value); + $valueFiltered = str_replace($locale['decimal_point'], '.', $valueFiltered); + + if (strval(floatval($valueFiltered)) != $valueFiltered) { + $this->_error(self::NOT_FLOAT); + return false; + } + + } else { + try { + if (!Zend_Locale_Format::isFloat($value, array('locale' => 'en')) && + !Zend_Locale_Format::isFloat($value, array('locale' => $this->_locale))) { + $this->_error(self::NOT_FLOAT); + return false; + } + } catch (Zend_Locale_Exception $e) { $this->_error(self::NOT_FLOAT); return false; } - } catch (Zend_Locale_Exception $e) { - $this->_error(self::NOT_FLOAT); - return false; } return true; diff --git a/libs/Zend/Validate/GreaterThan.php b/libs/Zend/Validate/GreaterThan.php index a9b7a21879..3c7b7931c9 100644 --- a/libs/Zend/Validate/GreaterThan.php +++ b/libs/Zend/Validate/GreaterThan.php @@ -1,4 +1,5 @@ <?php + /** * Zend Framework * @@ -14,20 +15,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: GreaterThan.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: GreaterThan.php 17470 2009-08-08 22:27:09Z thomas $ */ + /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; + /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 @@ -39,7 +42,7 @@ class Zend_Validate_GreaterThan extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_GREATER => "'%value%' is not greater than '%min%'", + self::NOT_GREATER => "'%value%' is not greater than '%min%'" ); /** @@ -59,24 +62,11 @@ class Zend_Validate_GreaterThan extends Zend_Validate_Abstract /** * Sets validator options * - * @param mixed|Zend_Config $min + * @param mixed $min * @return void */ public function __construct($min) { - if ($min instanceof Zend_Config) { - $min = $min->toArray(); - } - - if (is_array($min)) { - if (array_key_exists('min', $min)) { - $min = $min['min']; - } else { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception("Missing option 'min'"); - } - } - $this->setMin($min); } diff --git a/libs/Zend/Validate/Hex.php b/libs/Zend/Validate/Hex.php index b2080d3aaa..85d3e3a7a2 100644 --- a/libs/Zend/Validate/Hex.php +++ b/libs/Zend/Validate/Hex.php @@ -1,4 +1,5 @@ <?php + /** * Zend Framework * @@ -14,20 +15,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Hex.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: Hex.php 17470 2009-08-08 22:27:09Z thomas $ */ + /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; + /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 @@ -42,7 +45,7 @@ class Zend_Validate_Hex extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be a string", - self::NOT_HEX => "'%value%' has not only hexadecimal digit characters", + self::NOT_HEX => "'%value%' has not only hexadecimal digit characters" ); /** diff --git a/libs/Zend/Validate/Hostname.php b/libs/Zend/Validate/Hostname.php index 1732e69c77..dd254d5596 100644 --- a/libs/Zend/Validate/Hostname.php +++ b/libs/Zend/Validate/Hostname.php @@ -14,20 +14,20 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Hostname.php 21063 2010-02-15 23:00:17Z thomas $ + * @version $Id: Hostname.php 17141 2009-07-26 12:49:17Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * @see Zend_Validate_Ip */ -// require_once 'Zend/Validate/Ip.php'; +require_once 'Zend/Validate/Ip.php'; /** * Please note there are two standalone test scripts for testing IDN characters due to problems @@ -41,7 +41,7 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 @@ -64,13 +64,13 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract self::INVALID => "Invalid type given, value should be a string", 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_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", - self::CANNOT_DECODE_PUNYCODE => "'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded", + self::CANNOT_DECODE_PUNYCODE => "'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded" ); /** @@ -101,6 +101,27 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract 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; + + /** * Array of valid top-level-domains * * @see ftp://data.iana.org/TLD/tlds-alpha-by-domain.txt List of all TLDs by domain @@ -200,12 +221,6 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract 'DE' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿăąāćĉčċďđĕěėęēğĝġģĥħĭĩįīıĵķĺľļłńňņŋŏőōœĸŕřŗśŝšşťţŧŭůűũųūŵŷźžż]{1,63}$/iu'), 'DK' => array(1 => '/^[\x{002d}0-9a-zäéöü]{1,63}$/iu'), 'ES' => array(1 => '/^[\x{002d}0-9a-zàáçèéíïñòóúü·]{1,63}$/iu'), - 'EU' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿ]{1,63}$/iu', - 2 => '/^[\x{002d}0-9a-zāăąćĉċčďđēĕėęěĝğġģĥħĩīĭįıĵķĺļľŀłńņňʼnŋōŏőœŕŗřśŝšťŧũūŭůűųŵŷźżž]{1,63}$/iu', - 3 => '/^[\x{002d}0-9a-zșț]{1,63}$/iu', - 4 => '/^[\x{002d}0-9a-zΐάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώ]{1,63}$/iu', - 5 => '/^[\x{002d}0-9a-zабвгдежзийклмнопрстуфхцчшщъыьэюя]{1,63}$/iu', - 6 => '/^[\x{002d}0-9a-zἀ-ἇἐ-ἕἠ-ἧἰ-ἷὀ-ὅὐ-ὗὠ-ὧὰ-ώᾀ-ᾇᾐ-ᾗᾠ-ᾧᾰ-ᾴᾶᾷῂῃῄῆῇῐ-ΐῖῗῠ-ῧῲῳῴῶῷ]{1,63}$/iu'), 'FI' => array(1 => '/^[\x{002d}0-9a-zäåö]{1,63}$/iu'), 'GR' => array(1 => '/^[\x{002d}0-9a-zΆΈΉΊΌΎ-ΡΣ-ώἀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼῂῃῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲῳῴῶ-ῼ]{1,63}$/iu'), 'HK' => 'Zend/Validate/Hostname/Cn.php', @@ -305,13 +320,6 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract '网络' => array(1 => 20), ); - protected $_options = array( - 'allow' => self::ALLOW_DNS, - 'idn' => true, - 'tld' => true, - 'ip' => null - ); - /** * Sets validator options * @@ -322,77 +330,16 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract * @return void * @see http://www.iana.org/cctld/specifications-policies-cctlds-01apr02.htm Technical Specifications for ccTLDs */ - public function __construct($options = array()) + public function __construct($allow = self::ALLOW_DNS, $validateIdn = true, $validateTld = true, Zend_Validate_Ip $ipValidator = null) { - if ($options instanceof Zend_Config) { - $options = $options->toArray(); - } else if (!is_array($options)) { - $options = func_get_args(); - $temp['allow'] = array_shift($options); - if (!empty($options)) { - $temp['idn'] = array_shift($options); - } - - if (!empty($options)) { - $temp['tld'] = array_shift($options); - } - - if (!empty($options)) { - $temp['ip'] = array_shift($options); - } - - $options = $temp; - } - - $options += $this->_options; - $this->setOptions($options); - } - - /** - * Returns all set options - * - * @return array - */ - public function getOptions() - { - return $this->_options; - } - - /** - * Sets the options for this validator - * - * @param array $options - * @return Zend_Validate_Hostname - */ - public function setOptions($options) - { - if (array_key_exists('allow', $options)) { - $this->setAllow($options['allow']); - } + // Set allow options + $this->setAllow($allow); - if (array_key_exists('idn', $options)) { - $this->setValidateIdn($options['idn']); - } - - if (array_key_exists('tld', $options)) { - $this->setValidateTld($options['tld']); - } - - if (array_key_exists('ip', $options)) { - $this->setIpValidator($options['ip']); - } + // Set validation options + $this->_validateIdn = $validateIdn; + $this->_validateTld = $validateTld; - return $this; - } - - /** - * Returns the set ip validator - * - * @return Zend_Validate_Ip - */ - public function getIpValidator() - { - return $this->_options['ip']; + $this->setIpValidator($ipValidator); } /** @@ -404,9 +351,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract if ($ipValidator === null) { $ipValidator = new Zend_Validate_Ip(); } - - $this->_options['ip'] = $ipValidator; - return $this; + $this->_ipValidator = $ipValidator; } /** @@ -416,7 +361,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract */ public function getAllow() { - return $this->_options['allow']; + return $this->_allow; } /** @@ -427,21 +372,11 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract */ public function setAllow($allow) { - $this->_options['allow'] = $allow; + $this->_allow = $allow; return $this; } /** - * Returns the set idn option - * - * @return boolean - */ - public function getValidateIdn() - { - return $this->_options['idn']; - } - - /** * Set whether IDN domains are validated * * This only applies when DNS hostnames are validated @@ -450,18 +385,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract */ public function setValidateIdn ($allowed) { - $this->_options['idn'] = (bool) $allowed; - return $this; - } - - /** - * Returns the set tld option - * - * @return boolean - */ - public function getValidateTld() - { - return $this->_options['tld']; + $this->_validateIdn = (bool) $allowed; } /** @@ -473,8 +397,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract */ public function setValidateTld ($allowed) { - $this->_options['tld'] = (bool) $allowed; - return $this; + $this->_validateTld = (bool) $allowed; } /** @@ -494,10 +417,11 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract } $this->_setValue($value); + // Check input against IP address schema if (preg_match('/^[0-9.a-e:.]*$/i', $value) && - $this->_options['ip']->setTranslator($this->getTranslator())->isValid($value)) { - if (!($this->_options['allow'] & self::ALLOW_IP)) { + $this->_ipValidator->setTranslator($this->getTranslator())->isValid($value)) { + if (!($this->_allow & self::ALLOW_IP)) { $this->_error(self::IP_ADDRESS_NOT_ALLOWED); return false; } else { @@ -528,7 +452,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract // Match TLD against known list $this->_tld = strtolower($matches[1]); - if ($this->_options['tld']) { + if ($this->_validateTld) { if (!in_array($this->_tld, $this->_validTlds)) { $this->_error(self::UNKNOWN_TLD); $status = false; @@ -542,17 +466,18 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract * @see Zend_Validate_Hostname_Interface */ $regexChars = array(0 => '/^[a-z0-9\x2d]{1,63}$/i'); - if ($this->_options['idn'] && isset($this->_validIdns[strtoupper($this->_tld)])) { + if ($this->_validateIdn && isset($this->_validIdns[strtoupper($this->_tld)])) { if (is_string($this->_validIdns[strtoupper($this->_tld)])) { - $regexChars += include(dirname(__FILE__) . '/../../' . $this->_validIdns[strtoupper($this->_tld)]); + $regexChars += include($this->_validIdns[strtoupper($this->_tld)]); } else { $regexChars += $this->_validIdns[strtoupper($this->_tld)]; } } // Check each hostname part - $check = 0; + $valid = true; foreach ($domainParts as $domainPart) { + // Decode Punycode domainnames to IDN if (strpos($domainPart, 'xn--') === 0) { $domainPart = $this->decodePunycode(substr($domainPart, 4)); @@ -565,16 +490,20 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract if ((strpos($domainPart, '-') === 0) || ((strlen($domainPart) > 2) && (strpos($domainPart, '-', 2) == 2) && (strpos($domainPart, '-', 3) == 3)) || (strpos($domainPart, '-') === (strlen($domainPart) - 1))) { - $this->_error(self::INVALID_DASH); + $this->_error(self::INVALID_DASH); $status = false; break 2; } // Check each domain part - $checked = false; + $check = false; foreach($regexChars as $regexKey => $regexChar) { $status = @preg_match($regexChar, $domainPart); - if ($status > 0) { + if ($status === false) { + iconv_set_encoding('internal_encoding', $origenc); + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception('Internal error: DNS validation failed'); + } elseif ($status !== 0) { $length = 63; if (array_key_exists(strtoupper($this->_tld), $this->_idnLength) && (array_key_exists($regexKey, $this->_idnLength[strtoupper($this->_tld)]))) { @@ -584,22 +513,23 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract if (iconv_strlen($domainPart, 'UTF-8') > $length) { $this->_error(self::INVALID_HOSTNAME); } else { - $checked = true; - break; + $check = true; + break 2; } } } - if ($checked) { - ++$check; + if (!$check) { + $valid = false; } } - // If one of the labels doesn't match, the hostname is invalid - if ($check !== count($domainParts)) { + // 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); @@ -610,20 +540,28 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract iconv_set_encoding('internal_encoding', $origenc); // If the input passes as an Internet domain name, and domain names are allowed, then the hostname // passes validation - if ($status && ($this->_options['allow'] & self::ALLOW_DNS)) { + if ($status && ($this->_allow & self::ALLOW_DNS)) { return true; } - } else if ($this->_options['allow'] & self::ALLOW_DNS) { + } 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, $value); + 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->_options['allow'] & self::ALLOW_LOCAL; + $allowLocal = $this->_allow & self::ALLOW_LOCAL; if ($status && $allowLocal) { return true; } diff --git a/libs/Zend/Validate/Hostname/Biz.php b/libs/Zend/Validate/Hostname/Biz.php index 38762217d8..f2e3e7a009 100644 --- a/libs/Zend/Validate/Hostname/Biz.php +++ b/libs/Zend/Validate/Hostname/Biz.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Biz.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Biz.php 16971 2009-07-22 18:05:45Z mikaelkael $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ return array( diff --git a/libs/Zend/Validate/Hostname/Cn.php b/libs/Zend/Validate/Hostname/Cn.php index feee54ade2..1bcd91eb95 100644 --- a/libs/Zend/Validate/Hostname/Cn.php +++ b/libs/Zend/Validate/Hostname/Cn.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Cn.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Cn.php 16971 2009-07-22 18:05:45Z mikaelkael $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ return array( diff --git a/libs/Zend/Validate/Hostname/Com.php b/libs/Zend/Validate/Hostname/Com.php index 413971fec5..19290b300f 100644 --- a/libs/Zend/Validate/Hostname/Com.php +++ b/libs/Zend/Validate/Hostname/Com.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Com.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Com.php 16971 2009-07-22 18:05:45Z mikaelkael $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ return array( diff --git a/libs/Zend/Validate/Hostname/Jp.php b/libs/Zend/Validate/Hostname/Jp.php index 02f278e2bd..0888472e61 100644 --- a/libs/Zend/Validate/Hostname/Jp.php +++ b/libs/Zend/Validate/Hostname/Jp.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Jp.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Jp.php 16971 2009-07-22 18:05:45Z mikaelkael $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ return array( diff --git a/libs/Zend/Validate/Iban.php b/libs/Zend/Validate/Iban.php index 097cd32cbd..071651fd96 100644 --- a/libs/Zend/Validate/Iban.php +++ b/libs/Zend/Validate/Iban.php @@ -14,22 +14,22 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Iban.php 21563 2010-03-19 10:10:45Z thomas $ + * @version $Id: Iban.php 16971 2009-07-22 18:05:45Z mikaelkael $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * Validates IBAN Numbers (International Bank Account Numbers) * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_Iban extends Zend_Validate_Abstract @@ -44,9 +44,9 @@ class Zend_Validate_Iban extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOTSUPPORTED => "Unknown country within the IBAN '%value%'", - self::FALSEFORMAT => "'%value%' has a false IBAN format", - self::CHECKFAILED => "'%value%' has failed the IBAN check", + self::NOTSUPPORTED => "'%value%' does not have IBAN", + self::FALSEFORMAT => "'%value%' has a false format", + self::CHECKFAILED => "'%value%' has failed the IBAN check" ); /** @@ -106,31 +106,12 @@ class Zend_Validate_Iban extends Zend_Validate_Abstract /** * Sets validator options * - * @param string|Zend_Config|Zend_Locale $locale OPTIONAL + * @param string|Zend_Locale $locale OPTIONAL * @return void */ public function __construct($locale = null) { - if ($locale instanceof Zend_Config) { - $locale = $locale->toArray(); - } - - if (is_array($locale)) { - if (array_key_exists('locale', $locale)) { - $locale = $locale['locale']; - } else { - $locale = null; - } - } - - if ($locale !== false) { - // require_once 'Zend/Registry.php'; - if (Zend_Registry::isRegistered('Zend_Locale')) { - $locale = Zend_Registry::get('Zend_Locale'); - } - } - - if (!empty($locale)) { + if ($locale !== null) { $this->setLocale($locale); } } @@ -153,13 +134,11 @@ class Zend_Validate_Iban extends Zend_Validate_Abstract */ public function setLocale($locale = null) { - if ($locale !== false) { - // require_once 'Zend/Locale.php'; - $locale = Zend_Locale::findLocale($locale); - if (strlen($locale) < 4) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('Region must be given for IBAN validation'); - } + require_once 'Zend/Locale.php'; + $locale = Zend_Locale::findLocale($locale); + if (strlen($locale) < 4) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception('Region must be given for IBAN validation'); } $this->_locale = $locale; diff --git a/libs/Zend/Validate/Identical.php b/libs/Zend/Validate/Identical.php index 7b37574050..d1a046ea9f 100644 --- a/libs/Zend/Validate/Identical.php +++ b/libs/Zend/Validate/Identical.php @@ -14,18 +14,18 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Identical.php 22077 2010-05-02 13:44:46Z thomas $ + * @version $Id: Identical.php 17684 2009-08-20 09:20:36Z yoshida@zend.co.jp $ */ /** @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 @@ -42,7 +42,7 @@ class Zend_Validate_Identical extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_SAME => "The two given tokens do not match", + self::NOT_SAME => "The token '%token%' does not match the given token '%value%'", self::MISSING_TOKEN => 'No token was provided to match against', ); @@ -59,7 +59,6 @@ class Zend_Validate_Identical extends Zend_Validate_Abstract */ protected $_tokenString; protected $_token; - protected $_strict = true; /** * Sets validator options @@ -69,32 +68,12 @@ class Zend_Validate_Identical extends Zend_Validate_Abstract */ public function __construct($token = null) { - if ($token instanceof Zend_Config) { - $token = $token->toArray(); - } - - if (is_array($token) && array_key_exists('token', $token)) { - if (array_key_exists('strict', $token)) { - $this->setStrict($token['strict']); - } - - $this->setToken($token['token']); - } else if (null !== $token) { + if (null !== $token) { $this->setToken($token); } } /** - * Retrieve token - * - * @return string - */ - public function getToken() - { - return $this->_token; - } - - /** * Set token against which to compare * * @param mixed $token @@ -108,24 +87,13 @@ class Zend_Validate_Identical extends Zend_Validate_Abstract } /** - * Returns the strict parameter - * - * @return boolean - */ - public function getStrict() - { - return $this->_strict; - } - - /** - * Sets the strict parameter + * Retrieve token * - * @param Zend_Validate_Identical + * @return string */ - public function setStrict($strict) + public function getToken() { - $this->_strict = (boolean) $strict; - return $this; + return $this->_token; } /** @@ -135,26 +103,19 @@ class Zend_Validate_Identical extends Zend_Validate_Abstract * matches that token. * * @param mixed $value - * @param array $context * @return boolean */ - public function isValid($value, $context = null) + public function isValid($value) { $this->_setValue((string) $value); - - if (($context !== null) && isset($context) && array_key_exists($this->getToken(), $context)) { - $token = $context[$this->getToken()]; - } else { - $token = $this->getToken(); - } + $token = $this->getToken(); if ($token === null) { $this->_error(self::MISSING_TOKEN); return false; } - $strict = $this->getStrict(); - if (($strict && ($value !== $token)) || (!$strict && ($value != $token))) { + if ($value !== $token) { $this->_error(self::NOT_SAME); return false; } diff --git a/libs/Zend/Validate/InArray.php b/libs/Zend/Validate/InArray.php index 3b1870543c..56940eb1aa 100644 --- a/libs/Zend/Validate/InArray.php +++ b/libs/Zend/Validate/InArray.php @@ -1,4 +1,5 @@ <?php + /** * Zend Framework * @@ -14,31 +15,34 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: InArray.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: InArray.php 17470 2009-08-08 22:27:09Z thomas $ */ + /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; + /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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", + self::NOT_IN_ARRAY => "'%value%' was not found in the haystack" ); /** @@ -53,54 +57,19 @@ class Zend_Validate_InArray extends Zend_Validate_Abstract * * @var boolean */ - protected $_strict = false; - - /** - * Whether a recursive search should be done - * - * @var boolean - */ - protected $_recursive = false; + protected $_strict; /** * Sets validator options * - * @param array|Zend_Config $haystack + * @param array $haystack + * @param boolean $strict * @return void */ - public function __construct($options) + public function __construct(array $haystack, $strict = false) { - if ($options instanceof Zend_Config) { - $options = $options->toArray(); - } else if (!is_array($options)) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('Array expected as parameter'); - } else { - $count = func_num_args(); - $temp = array(); - if ($count > 1) { - $temp['haystack'] = func_get_arg(0); - $temp['strict'] = func_get_arg(1); - $options = $temp; - } else { - $temp = func_get_arg(0); - if (!array_key_exists('haystack', $options)) { - $options = array(); - $options['haystack'] = $temp; - } else { - $options = $temp; - } - } - } - - $this->setHaystack($options['haystack']); - if (array_key_exists('strict', $options)) { - $this->setStrict($options['strict']); - } - - if (array_key_exists('recursive', $options)) { - $this->setRecursive($options['recursive']); - } + $this->setHaystack($haystack) + ->setStrict($strict); } /** @@ -143,29 +112,7 @@ class Zend_Validate_InArray extends Zend_Validate_Abstract */ public function setStrict($strict) { - $this->_strict = (boolean) $strict; - return $this; - } - - /** - * Returns the recursive option - * - * @return boolean - */ - public function getRecursive() - { - return $this->_recursive; - } - - /** - * Sets the recursive option - * - * @param boolean $recursive - * @return Zend_Validate_InArray Provides a fluent interface - */ - public function setRecursive($recursive) - { - $this->_recursive = (boolean) $recursive; + $this->_strict = $strict; return $this; } @@ -181,24 +128,11 @@ class Zend_Validate_InArray extends Zend_Validate_Abstract public function isValid($value) { $this->_setValue($value); - if ($this->getRecursive()) { - $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->_haystack)); - foreach($iterator as $element) { - if ($this->_strict) { - if ($element === $value) { - return true; - } - } else if ($element == $value) { - return true; - } - } - } else { - if (in_array($value, $this->_haystack, $this->_strict)) { - return true; - } + if (!in_array($value, $this->_haystack, $this->_strict)) { + $this->_error(self::NOT_IN_ARRAY); + return false; } - - $this->_error(self::NOT_IN_ARRAY); - return false; + return true; } + } diff --git a/libs/Zend/Validate/Int.php b/libs/Zend/Validate/Int.php index 89fa168627..1e34ee3427 100644 --- a/libs/Zend/Validate/Int.php +++ b/libs/Zend/Validate/Int.php @@ -14,25 +14,25 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Int.php 20532 2010-01-22 20:18:23Z thomas $ + * @version $Id: Int.php 17470 2009-08-08 22:27:09Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * @see Zend_Locale_Format */ -// require_once 'Zend/Locale/Format.php'; +require_once 'Zend/Locale/Format.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 @@ -44,8 +44,8 @@ class Zend_Validate_Int extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::INVALID => "Invalid type given, value should be string or integer", - self::NOT_INT => "'%value%' does not appear to be an integer", + self::INVALID => "Invalid type given, value should be a string or a integer", + self::NOT_INT => "'%value%' does not appear to be an integer" ); protected $_locale; @@ -53,29 +53,10 @@ class Zend_Validate_Int extends Zend_Validate_Abstract /** * Constructor for the integer validator * - * @param string|Zend_Config|Zend_Locale $locale + * @param string|Zend_Locale $locale */ public function __construct($locale = null) { - if ($locale instanceof Zend_Config) { - $locale = $locale->toArray(); - } - - if (is_array($locale)) { - if (array_key_exists('locale', $locale)) { - $locale = $locale['locale']; - } else { - $locale = null; - } - } - - if (empty($locale)) { - // require_once 'Zend/Registry.php'; - if (Zend_Registry::isRegistered('Zend_Locale')) { - $locale = Zend_Registry::get('Zend_Locale'); - } - } - if ($locale !== null) { $this->setLocale($locale); } @@ -96,7 +77,7 @@ class Zend_Validate_Int extends Zend_Validate_Abstract */ public function setLocale($locale = null) { - // require_once 'Zend/Locale.php'; + require_once 'Zend/Locale.php'; $this->_locale = Zend_Locale::findLocale($locale); return $this; } @@ -116,10 +97,6 @@ class Zend_Validate_Int extends Zend_Validate_Abstract return false; } - if (is_int($value)) { - return true; - } - $this->_setValue($value); if ($this->_locale === null) { $locale = localeconv(); @@ -133,7 +110,8 @@ class Zend_Validate_Int extends Zend_Validate_Abstract } else { try { - if (!Zend_Locale_Format::isInteger($value, array('locale' => $this->_locale))) { + if (!Zend_Locale_Format::isInteger($value, array('locale' => 'en')) && + !Zend_Locale_Format::isInteger($value, array('locale' => $this->_locale))) { $this->_error(self::NOT_INT); return false; } diff --git a/libs/Zend/Validate/Interface.php b/libs/Zend/Validate/Interface.php index 9dfca94219..842a57a8d1 100644 --- a/libs/Zend/Validate/Interface.php +++ b/libs/Zend/Validate/Interface.php @@ -1,4 +1,5 @@ <?php + /** * Zend Framework * @@ -14,15 +15,16 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Interface.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: Interface.php 16223 2009-06-21 20:04:53Z thomas $ */ + /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ interface Zend_Validate_Interface @@ -51,4 +53,19 @@ interface Zend_Validate_Interface * @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(); + } diff --git a/libs/Zend/Validate/Ip.php b/libs/Zend/Validate/Ip.php index 992e60a787..a89bb36fe7 100644 --- a/libs/Zend/Validate/Ip.php +++ b/libs/Zend/Validate/Ip.php @@ -14,20 +14,20 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ip.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: Ip.php 17470 2009-08-08 22:27:09Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 @@ -40,78 +40,10 @@ class Zend_Validate_Ip extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be a string", - self::NOT_IP_ADDRESS => "'%value%' does not appear to be a valid IP address", + self::NOT_IP_ADDRESS => "'%value%' does not appear to be a valid IP address" ); /** - * internal options - * - * @var array - */ - protected $_options = array( - 'allowipv6' => true, - 'allowipv4' => true - ); - - /** - * Sets validator options - * - * @param array $options OPTIONAL Options to set, see the manual for all available options - * @return void - */ - public function __construct($options = array()) - { - if ($options instanceof Zend_Config) { - $options = $options->toArray(); - } else if (!is_array($options)) { - $options = func_get_args(); - $temp['allowipv6'] = array_shift($options); - if (!empty($options)) { - $temp['allowipv4'] = array_shift($options); - } - - $options = $temp; - } - - $options += $this->_options; - $this->setOptions($options); - } - - /** - * Returns all set options - * - * @return array - */ - public function getOptions() - { - return $this->_options; - } - - /** - * Sets the options for this validator - * - * @param array $options - * @return Zend_Validate_Ip - */ - public function setOptions($options) - { - if (array_key_exists('allowipv6', $options)) { - $this->_options['allowipv6'] = (boolean) $options['allowipv6']; - } - - if (array_key_exists('allowipv4', $options)) { - $this->_options['allowipv4'] = (boolean) $options['allowipv4']; - } - - if (!$this->_options['allowipv4'] && !$this->_options['allowipv6']) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('Nothing to validate. Check your options'); - } - - return $this; - } - - /** * Defined by Zend_Validate_Interface * * Returns true if and only if $value is a valid IP address @@ -127,65 +59,18 @@ class Zend_Validate_Ip extends Zend_Validate_Abstract } $this->_setValue($value); - if (($this->_options['allowipv4'] && !$this->_options['allowipv6'] && !$this->_validateIPv4($value)) || - (!$this->_options['allowipv4'] && $this->_options['allowipv6'] && !$this->_validateIPv6($value)) || - ($this->_options['allowipv4'] && $this->_options['allowipv6'] && !$this->_validateIPv4($value) && !$this->_validateIPv6($value))) { - $this->_error(self::NOT_IP_ADDRESS); - return false; - } - - return true; - } - - /** - * Validates an IPv4 address - * - * @param string $value - */ - protected function _validateIPv4($value) { - $ip2long = ip2long($value); - if($ip2long === false) { - return false; - } - - return $value == long2ip($ip2long); - } - /** - * Validates an IPv6 address - * - * @param string $value Value to check against - * @return boolean True when $value is a valid ipv6 address - * False otherwise - */ - protected function _validateIPv6($value) { - if (strlen($value) < 3) { - return $value == '::'; - } - - if (strpos($value, '.')) { - $lastcolon = strrpos($value, ':'); - if (!($lastcolon && $this->_validateIPv4(substr($value, $lastcolon + 1)))) { + if ((ip2long($value) === false) || (long2ip(ip2long($value)) !== $value)) { + if (!function_exists('inet_pton')) { + $this->_error(self::NOT_IP_ADDRESS); + return false; + } else if ((@inet_pton($value) === false) ||(inet_ntop(@inet_pton($value)) !== $value)) { + $this->_error(self::NOT_IP_ADDRESS); return false; } - - $value = substr($value, 0, $lastcolon) . ':0:0'; } - if (strpos($value, '::') === false) { - return preg_match('/\A(?:[a-f0-9]{1,4}:){7}[a-f0-9]{1,4}\z/i', $value); - } - - $colonCount = substr_count($value, ':'); - if ($colonCount < 8) { - return preg_match('/\A(?::|(?:[a-f0-9]{1,4}:)+):(?:(?:[a-f0-9]{1,4}:)*[a-f0-9]{1,4})?\z/i', $value); - } - - // special case with ending or starting double colon - if ($colonCount == 8) { - return preg_match('/\A(?:::)?(?:[a-f0-9]{1,4}:){6}[a-f0-9]{1,4}(?:::)?\z/i', $value); - } - - return false; + return true; } + } diff --git a/libs/Zend/Validate/Isbn.php b/libs/Zend/Validate/Isbn.php deleted file mode 100644 index e977871b20..0000000000 --- a/libs/Zend/Validate/Isbn.php +++ /dev/null @@ -1,279 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Isbn.php 21761 2010-04-04 21:37:18Z thomas $ - */ - -/** - * @see Zend_Validate_Abstract - */ -// require_once 'Zend/Validate/Abstract.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_Isbn extends Zend_Validate_Abstract -{ - const AUTO = 'auto'; - const ISBN10 = '10'; - const ISBN13 = '13'; - const INVALID = 'isbnInvalid'; - const NO_ISBN = 'isbnNoIsbn'; - - /** - * Validation failure message template definitions. - * - * @var array - */ - protected $_messageTemplates = array( - self::INVALID => "Invalid type given, value should be string or integer", - self::NO_ISBN => "'%value%' is no valid ISBN number", - ); - - /** - * Allowed type. - * - * @var string - */ - protected $_type = self::AUTO; - - /** - * Separator character. - * - * @var string - */ - protected $_separator = ''; - - /** - * Set up options. - * - * @param Zend_Config|array $options - * @throws Zend_Validate_Exception When $options is not valid - * @return void - */ - public function __construct($options = array()) - { - // prepare options - if ($options instanceof Zend_Config) { - $options = $options->toArray(); - } - if (!is_array($options)) { - /** - * @see Zend_Validate_Exception - */ - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('Invalid options provided.'); - } - - // set type - if (array_key_exists('type', $options)) { - $this->setType($options['type']); - } - - // set separator - if (array_key_exists('separator', $options)) { - $this->setSeparator($options['separator']); - } - } - - /** - * Detect input format. - * - * @return string - */ - protected function _detectFormat() - { - // prepare separator and pattern list - $sep = quotemeta($this->_separator); - $patterns = array(); - $lengths = array(); - - // check for ISBN-10 - if ($this->_type == self::ISBN10 || $this->_type == self::AUTO) { - if (empty($sep)) { - $pattern = '/^[0-9]{9}[0-9X]{1}$/'; - $length = 10; - } else { - $pattern = "/^[0-9]{1,7}[{$sep}]{1}[0-9]{1,7}[{$sep}]{1}[0-9]{1,7}[{$sep}]{1}[0-9X]{1}$/"; - $length = 13; - } - - $patterns[$pattern] = self::ISBN10; - $lengths[$pattern] = $length; - } - - // check for ISBN-13 - if ($this->_type == self::ISBN13 || $this->_type == self::AUTO) { - if (empty($sep)) { - $pattern = '/^[0-9]{13}$/'; - $length = 13; - } else { - $pattern = "/^[0-9]{1,9}[{$sep}]{1}[0-9]{1,5}[{$sep}]{1}[0-9]{1,9}[{$sep}]{1}[0-9]{1,9}[{$sep}]{1}[0-9]{1}$/"; - $length = 17; - } - - $patterns[$pattern] = self::ISBN13; - $lengths[$pattern] = $length; - } - - // check pattern list - foreach ($patterns as $pattern => $type) { - if ((strlen($this->_value) == $lengths[$pattern]) && preg_match($pattern, $this->_value)) { - return $type; - } - } - - return null; - } - - /** - * Defined by Zend_Validate_Interface. - * - * Returns true if and only if $value is a valid ISBN. - * - * @param string $value - * @return boolean - */ - public function isValid($value) - { - if (!is_string($value) && !is_int($value)) { - $this->_error(self::INVALID); - return false; - } - - $value = (string) $value; - $this->_setValue($value); - - switch ($this->_detectFormat()) { - case self::ISBN10: - // sum - $isbn10 = str_replace($this->_separator, '', $value); - $sum = 0; - for ($i = 0; $i < 9; $i++) { - $sum += (10 - $i) * $isbn10{$i}; - } - - // checksum - $checksum = 11 - ($sum % 11); - if ($checksum == 11) { - $checksum = '0'; - } elseif ($checksum == 10) { - $checksum = 'X'; - } - break; - - case self::ISBN13: - // sum - $isbn13 = str_replace($this->_separator, '', $value); - $sum = 0; - for ($i = 0; $i < 12; $i++) { - if ($i % 2 == 0) { - $sum += $isbn13{$i}; - } else { - $sum += 3 * $isbn13{$i}; - } - } - // checksum - $checksum = 10 - ($sum % 10); - if ($checksum == 10) { - $checksum = '0'; - } - break; - - default: - $this->_error(self::NO_ISBN); - return false; - } - - // validate - if (substr($this->_value, -1) != $checksum) { - $this->_error(self::NO_ISBN); - return false; - } - return true; - } - - /** - * Set separator characters. - * - * It is allowed only empty string, hyphen and space. - * - * @param string $separator - * @throws Zend_Validate_Exception When $separator is not valid - * @return Zend_Validate_Isbn Provides a fluent interface - */ - public function setSeparator($separator) - { - // check separator - if (!in_array($separator, array('-', ' ', ''))) { - /** - * @see Zend_Validate_Exception - */ - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('Invalid ISBN separator.'); - } - - $this->_separator = $separator; - return $this; - } - - /** - * Get separator characters. - * - * @return string - */ - public function getSeparator() - { - return $this->_separator; - } - - /** - * Set allowed ISBN type. - * - * @param string $type - * @throws Zend_Validate_Exception When $type is not valid - * @return Zend_Validate_Isbn Provides a fluent interface - */ - public function setType($type) - { - // check type - if (!in_array($type, array(self::AUTO, self::ISBN10, self::ISBN13))) { - /** - * @see Zend_Validate_Exception - */ - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('Invalid ISBN type'); - } - - $this->_type = $type; - return $this; - } - - /** - * Get allowed ISBN type. - * - * @return string - */ - public function getType() - { - return $this->_type; - } -} diff --git a/libs/Zend/Validate/LessThan.php b/libs/Zend/Validate/LessThan.php index 213c766f88..5d4e155559 100644 --- a/libs/Zend/Validate/LessThan.php +++ b/libs/Zend/Validate/LessThan.php @@ -1,4 +1,5 @@ <?php + /** * Zend Framework * @@ -14,24 +15,27 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: LessThan.php 20182 2010-01-10 21:12:01Z thomas $ + * @version $Id: LessThan.php 17470 2009-08-08 22:27:09Z thomas $ */ + /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; + /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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'; /** @@ -58,24 +62,11 @@ class Zend_Validate_LessThan extends Zend_Validate_Abstract /** * Sets validator options * - * @param mixed|Zend_Config $max + * @param mixed $max * @return void */ public function __construct($max) { - if ($max instanceof Zend_Config) { - $max = $max->toArray(); - } - - if (is_array($max)) { - if (array_key_exists('max', $max)) { - $max = $max['max']; - } else { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception("Missing option 'max'"); - } - } - $this->setMax($max); } diff --git a/libs/Zend/Validate/NotEmpty.php b/libs/Zend/Validate/NotEmpty.php index e370459cf9..304cf4fe70 100644 --- a/libs/Zend/Validate/NotEmpty.php +++ b/libs/Zend/Validate/NotEmpty.php @@ -14,51 +14,27 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: NotEmpty.php 20193 2010-01-11 10:40:43Z thomas $ + * @version $Id: NotEmpty.php 18186 2009-09-17 18:57:00Z matthew $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 BOOLEAN = 1; - const INTEGER = 2; - const FLOAT = 4; - const STRING = 8; - const ZERO = 16; - const EMPTY_ARRAY = 32; - const NULL = 64; - const PHP = 127; - const SPACE = 128; - const ALL = 255; - const INVALID = 'notEmptyInvalid'; const IS_EMPTY = 'isEmpty'; - protected $_constants = array( - self::BOOLEAN => 'boolean', - self::INTEGER => 'integer', - self::FLOAT => 'float', - self::STRING => 'string', - self::ZERO => 'zero', - self::EMPTY_ARRAY => 'array', - self::NULL => 'null', - self::PHP => 'php', - self::SPACE => 'space', - self::ALL => 'all' - ); - /** * @var array */ @@ -68,80 +44,6 @@ class Zend_Validate_NotEmpty extends Zend_Validate_Abstract ); /** - * Internal type to detect - * - * @var integer - */ - protected $_type = 237; - - /** - * Constructor - * - * @param string|array|Zend_Config $options OPTIONAL - */ - public function __construct($options = null) - { - if ($options instanceof Zend_Config) { - $options = $options->toArray(); - } else if (!is_array($options)) { - $options = func_get_args(); - $temp = array(); - if (!empty($options)) { - $temp['type'] = array_shift($options); - } - - $options = $temp; - } - - if (is_array($options) && array_key_exists('type', $options)) { - $this->setType($options['type']); - } - } - - /** - * Returns the set types - * - * @return array - */ - public function getType() - { - return $this->_type; - } - - /** - * Set the types - * - * @param integer|array $type - * @throws Zend_Validate_Exception - * @return Zend_Validate_NotEmpty - */ - public function setType($type = null) - { - if (is_array($type)) { - $detected = 0; - foreach($type as $value) { - if (is_int($value)) { - $detected += $value; - } else if (in_array($value, $this->_constants)) { - $detected += array_search($value, $this->_constants); - } - } - - $type = $detected; - } else if (is_string($type) && in_array($type, $this->_constants)) { - $type = array_search($type, $this->_constants); - } - - if (!is_int($type) || ($type < 0) || ($type > self::ALL)) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('Unknown type'); - } - - $this->_type = $type; - return $this; - } - - /** * Defined by Zend_Validate_Interface * * Returns true if and only if $value is not an empty value. @@ -157,81 +59,21 @@ class Zend_Validate_NotEmpty extends Zend_Validate_Abstract return false; } - $type = $this->getType(); $this->_setValue($value); - - // SPACE (' ') - if ($type >= self::SPACE) { - $type -= self::SPACE; - if (is_string($value) && (preg_match('/^\s+$/s', $value))) { - $this->_error(self::IS_EMPTY); - return false; - } - } - - // NULL (null) - if ($type >= self::NULL) { - $type -= self::NULL; - if (is_null($value)) { - $this->_error(self::IS_EMPTY); - return false; - } - } - - // EMPTY_ARRAY (array()) - if ($type >= self::EMPTY_ARRAY) { - $type -= self::EMPTY_ARRAY; - if (is_array($value) && ($value == array())) { - $this->_error(self::IS_EMPTY); - return false; - } - } - - // ZERO ('0') - if ($type >= self::ZERO) { - $type -= self::ZERO; - if (is_string($value) && ($value == '0')) { - $this->_error(self::IS_EMPTY); - return false; - } - } - - // STRING ('') - if ($type >= self::STRING) { - $type -= self::STRING; - if (is_string($value) && ($value == '')) { - $this->_error(self::IS_EMPTY); - return false; - } - } - - // FLOAT (0.0) - if ($type >= self::FLOAT) { - $type -= self::FLOAT; - if (is_float($value) && ($value == 0.0)) { - $this->_error(self::IS_EMPTY); - return false; - } - } - - // INTEGER (0) - if ($type >= self::INTEGER) { - $type -= self::INTEGER; - if (is_int($value) && ($value == 0)) { - $this->_error(self::IS_EMPTY); - return false; - } - } - - // BOOLEAN (false) - if ($type >= self::BOOLEAN) { - $type -= self::BOOLEAN; - if (is_bool($value) && ($value == false)) { - $this->_error(self::IS_EMPTY); - return false; - } + if (is_string($value) + && (('' === $value) + || preg_match('/^\s+$/s', $value)) + ) { + $this->_error(self::IS_EMPTY); + return false; + } elseif (is_int($value) && (0 === $value)) { + return true; + } elseif (!is_string($value) && empty($value)) { + $this->_error(self::IS_EMPTY); + return false; } return true; } + } diff --git a/libs/Zend/Validate/PostCode.php b/libs/Zend/Validate/PostCode.php deleted file mode 100644 index 1ba58a996b..0000000000 --- a/libs/Zend/Validate/PostCode.php +++ /dev/null @@ -1,210 +0,0 @@ -<?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-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: PostCode.php 21487 2010-03-14 10:17:35Z thomas $ - */ - -/** - * @see Zend_Validate_Abstract - */ -// require_once 'Zend/Validate/Abstract.php'; - -/** - * @see Zend_Locale_Format - */ -// require_once 'Zend/Locale/Format.php'; - -/** - * @category Zend - * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Validate_PostCode extends Zend_Validate_Abstract -{ - const INVALID = 'postcodeInvalid'; - const NO_MATCH = 'postcodeNoMatch'; - - /** - * @var array - */ - protected $_messageTemplates = array( - self::INVALID => "Invalid type given. The value should be a string or a integer", - self::NO_MATCH => "'%value%' does not appear to be a postal code", - ); - - /** - * Locale to use - * - * @var string - */ - protected $_locale; - - /** - * Manual postal code format - * - * @var unknown_type - */ - protected $_format; - - /** - * Constructor for the integer validator - * - * Accepts either a string locale, a Zend_Locale object, or an array or - * Zend_Config object containing the keys "locale" and/or "format". - * - * @param string|Zend_Locale|array|Zend_Config $options - * @throws Zend_Validate_Exception On empty format - */ - public function __construct($options = null) - { - if ($options instanceof Zend_Config) { - $options = $options->toArray(); - } - - if (empty($options)) { - // require_once 'Zend/Registry.php'; - if (Zend_Registry::isRegistered('Zend_Locale')) { - $this->setLocale(Zend_Registry::get('Zend_Locale')); - } - } elseif (is_array($options)) { - // Received - if (array_key_exists('locale', $options)) { - $this->setLocale($options['locale']); - } - - if (array_key_exists('format', $options)) { - $this->setFormat($options['format']); - } - } elseif ($options instanceof Zend_Locale || is_string($options)) { - // Received Locale object or string locale - $this->setLocale($options); - } - - $format = $this->getFormat(); - if (empty($format)) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception("A postcode-format string has to be given for validation"); - } - } - - /** - * Returns the set locale - * - * @return string|Zend_Locale The set locale - */ - public function getLocale() - { - return $this->_locale; - } - - /** - * Sets the locale to use - * - * @param string|Zend_Locale $locale - * @throws Zend_Validate_Exception On unrecognised region - * @throws Zend_Validate_Exception On not detected format - * @return Zend_Validate_PostCode Provides fluid interface - */ - public function setLocale($locale = null) - { - // require_once 'Zend/Locale.php'; - $this->_locale = Zend_Locale::findLocale($locale); - $locale = new Zend_Locale($this->_locale); - $region = $locale->getRegion(); - if (empty($region)) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception("Unable to detect a region for the locale '$locale'"); - } - - $format = Zend_Locale::getTranslation( - $locale->getRegion(), - 'postaltoterritory', - $this->_locale - ); - - if (empty($format)) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception("Unable to detect a postcode format for the region '{$locale->getRegion()}'"); - } - - $this->setFormat($format); - return $this; - } - - /** - * Returns the set postal code format - * - * @return string - */ - public function getFormat() - { - return $this->_format; - } - - /** - * Sets a self defined postal format as regex - * - * @param string $format - * @throws Zend_Validate_Exception On empty format - * @return Zend_Validate_PostCode Provides fluid interface - */ - public function setFormat($format) - { - if (empty($format) || !is_string($format)) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception("A postcode-format string has to be given for validation"); - } - - if ($format[0] !== '/') { - $format = '/^' . $format; - } - - if ($format[strlen($format) - 1] !== '/') { - $format .= '$/'; - } - - $this->_format = $format; - return $this; - } - - /** - * Defined by Zend_Validate_Interface - * - * Returns true if and only if $value is a valid postalcode - * - * @param string $value - * @return boolean - */ - public function isValid($value) - { - $this->_setValue($value); - if (!is_string($value) && !is_int($value)) { - $this->_error(self::INVALID); - return false; - } - - $format = $this->getFormat(); - if (!preg_match($format, $value)) { - $this->_error(self::NO_MATCH); - return false; - } - - return true; - } -} diff --git a/libs/Zend/Validate/Regex.php b/libs/Zend/Validate/Regex.php index e46143287f..e4707f5f60 100644 --- a/libs/Zend/Validate/Regex.php +++ b/libs/Zend/Validate/Regex.php @@ -1,4 +1,5 @@ <?php + /** * Zend Framework * @@ -14,35 +15,35 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Regex.php 21574 2010-03-19 20:00:37Z thomas $ + * @version $Id: Regex.php 17470 2009-08-08 22:27:09Z thomas $ */ + /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; + /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 INVALID = 'regexInvalid'; const NOT_MATCH = 'regexNotMatch'; - const ERROROUS = 'regexErrorous'; /** * @var array */ protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be string, integer or float", - self::NOT_MATCH => "'%value%' does not match against pattern '%pattern%'", - self::ERROROUS => "There was an internal error while using the pattern '%pattern%'", + self::NOT_MATCH => "'%value%' does not match against pattern '%pattern%'" ); /** @@ -62,25 +63,11 @@ class Zend_Validate_Regex extends Zend_Validate_Abstract /** * Sets validator options * - * @param string|Zend_Config $pattern - * @throws Zend_Validate_Exception On missing 'pattern' parameter + * @param string $pattern * @return void */ public function __construct($pattern) { - if ($pattern instanceof Zend_Config) { - $pattern = $pattern->toArray(); - } - - if (is_array($pattern)) { - if (array_key_exists('pattern', $pattern)) { - $pattern = $pattern['pattern']; - } else { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception("Missing option 'pattern'"); - } - } - $this->setPattern($pattern); } @@ -98,19 +85,11 @@ class Zend_Validate_Regex extends Zend_Validate_Abstract * Sets the pattern option * * @param string $pattern - * @throws Zend_Validate_Exception if there is a fatal error in pattern matching * @return Zend_Validate_Regex Provides a fluent interface */ public function setPattern($pattern) { $this->_pattern = (string) $pattern; - $status = @preg_match($this->_pattern, "Test"); - - if (false === $status) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception("Internal error while using the pattern '$this->_pattern'"); - } - return $this; } @@ -120,6 +99,7 @@ class Zend_Validate_Regex extends Zend_Validate_Abstract * 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) @@ -133,15 +113,14 @@ class Zend_Validate_Regex extends Zend_Validate_Abstract $status = @preg_match($this->_pattern, $value); if (false === $status) { - $this->_error(self::ERROROUS); - return false; + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception("Internal error matching pattern '$this->_pattern' against value '$value'"); } - if (!$status) { $this->_error(self::NOT_MATCH); return false; } - return true; } + } diff --git a/libs/Zend/Validate/Sitemap/Changefreq.php b/libs/Zend/Validate/Sitemap/Changefreq.php index 6f023856dc..9ff2715d20 100644 --- a/libs/Zend/Validate/Sitemap/Changefreq.php +++ b/libs/Zend/Validate/Sitemap/Changefreq.php @@ -15,15 +15,15 @@ * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Changefreq.php 21365 2010-03-07 09:38:41Z thomas $ + * @version $Id: Changefreq.php 17470 2009-08-08 22:27:09Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * Validates whether a given value is valid as a sitemap <changefreq> value @@ -33,7 +33,7 @@ * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_Sitemap_Changefreq extends Zend_Validate_Abstract @@ -42,8 +42,7 @@ class Zend_Validate_Sitemap_Changefreq extends Zend_Validate_Abstract * Validation key for not valid * */ - const NOT_VALID = 'sitemapChangefreqNotValid'; - const INVALID = 'sitemapChangefreqInvalid'; + const NOT_VALID = 'invalidSitemapChangefreq'; /** * Validation failure message template definitions @@ -51,8 +50,7 @@ class Zend_Validate_Sitemap_Changefreq extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_VALID => "'%value%' is no valid sitemap changefreq", - self::INVALID => "Invalid type given, the value should be a string", + self::NOT_VALID => "'%value%' is not a valid sitemap changefreq", ); /** @@ -75,12 +73,8 @@ class Zend_Validate_Sitemap_Changefreq extends Zend_Validate_Abstract */ public function isValid($value) { - if (!is_string($value)) { - $this->_error(self::INVALID); - return false; - } - $this->_setValue($value); + if (!is_string($value)) { return false; } diff --git a/libs/Zend/Validate/Sitemap/Lastmod.php b/libs/Zend/Validate/Sitemap/Lastmod.php index aa2266ecd9..4f01d1a781 100644 --- a/libs/Zend/Validate/Sitemap/Lastmod.php +++ b/libs/Zend/Validate/Sitemap/Lastmod.php @@ -15,15 +15,15 @@ * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Lastmod.php 21365 2010-03-07 09:38:41Z thomas $ + * @version $Id: Lastmod.php 16971 2009-07-22 18:05:45Z mikaelkael $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * Validates whether a given value is valid as a sitemap <lastmod> value @@ -33,7 +33,7 @@ * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_Sitemap_Lastmod extends Zend_Validate_Abstract @@ -42,14 +42,13 @@ class Zend_Validate_Sitemap_Lastmod extends Zend_Validate_Abstract * Regular expression to use when validating * */ - const LASTMOD_REGEX = '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])(T([0-1][0-9]|2[0-3])(:[0-5][0-9])(:[0-5][0-9])?(\\+|-)([0-1][0-9]|2[0-3]):[0-5][0-9])?$/'; + const LASTMOD_REGEX = '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])(T([0-1][0-9]|2[0-3])(:[0-5][0-9]){2}(\\+|-)([0-1][0-9]|2[0-3]):[0-5][0-9])?$/m'; /** * Validation key for not valid * */ - const NOT_VALID = 'sitemapLastmodNotValid'; - const INVALID = 'sitemapLastmodInvalid'; + const NOT_VALID = 'invalidSitemapLastmod'; /** * Validation failure message template definitions @@ -57,8 +56,7 @@ class Zend_Validate_Sitemap_Lastmod extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_VALID => "'%value%' is no valid sitemap lastmod", - self::INVALID => "Invalid type given, the value should be a string", + self::NOT_VALID => "'%value%' is not a valid sitemap lastmod", ); /** @@ -71,18 +69,13 @@ class Zend_Validate_Sitemap_Lastmod extends Zend_Validate_Abstract */ public function isValid($value) { - if (!is_string($value)) { - $this->_error(self::INVALID); - return false; - } - $this->_setValue($value); - $result = @preg_match(self::LASTMOD_REGEX, $value); - if ($result != 1) { - $this->_error(self::NOT_VALID); + + if (!is_string($value)) { return false; } - return true; + return @preg_match(self::LASTMOD_REGEX, $value) == 1; } + } diff --git a/libs/Zend/Validate/Sitemap/Loc.php b/libs/Zend/Validate/Sitemap/Loc.php index 180f669a01..92d5272030 100644 --- a/libs/Zend/Validate/Sitemap/Loc.php +++ b/libs/Zend/Validate/Sitemap/Loc.php @@ -15,20 +15,20 @@ * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Loc.php 21365 2010-03-07 09:38:41Z thomas $ + * @version $Id: Loc.php 16971 2009-07-22 18:05:45Z mikaelkael $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * @see Zend_Uri */ -// require_once 'Zend/Uri.php'; +require_once 'Zend/Uri.php'; /** * Validates whether a given value is valid as a sitemap <loc> value @@ -38,7 +38,7 @@ * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_Sitemap_Loc extends Zend_Validate_Abstract @@ -47,8 +47,7 @@ class Zend_Validate_Sitemap_Loc extends Zend_Validate_Abstract * Validation key for not valid * */ - const NOT_VALID = 'sitemapLocNotValid'; - const INVALID = 'sitemapLocInvalid'; + const NOT_VALID = 'invalidSitemapLoc'; /** * Validation failure message template definitions @@ -56,8 +55,7 @@ class Zend_Validate_Sitemap_Loc extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_VALID => "'%value%' is no valid sitemap location", - self::INVALID => "Invalid type given, the value should be a string", + self::NOT_VALID => "'%value%' is not a valid sitemap location", ); /** @@ -70,18 +68,12 @@ class Zend_Validate_Sitemap_Loc extends Zend_Validate_Abstract */ public function isValid($value) { - if (!is_string($value)) { - $this->_error(self::INVALID); - return false; - } - $this->_setValue($value); - $result = Zend_Uri::check($value); - if ($result !== true) { - $this->_error(self::NOT_VALID); + + if (!is_string($value)) { return false; } - return true; + return Zend_Uri::check($value); } } diff --git a/libs/Zend/Validate/Sitemap/Priority.php b/libs/Zend/Validate/Sitemap/Priority.php index 58772d5b2d..3568a9fc0f 100644 --- a/libs/Zend/Validate/Sitemap/Priority.php +++ b/libs/Zend/Validate/Sitemap/Priority.php @@ -15,15 +15,15 @@ * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Priority.php 21365 2010-03-07 09:38:41Z thomas $ + * @version $Id: Priority.php 16971 2009-07-22 18:05:45Z mikaelkael $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * Validates whether a given value is valid as a sitemap <priority> value @@ -33,7 +33,7 @@ * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_Sitemap_Priority extends Zend_Validate_Abstract @@ -42,8 +42,7 @@ class Zend_Validate_Sitemap_Priority extends Zend_Validate_Abstract * Validation key for not valid * */ - const NOT_VALID = 'sitemapPriorityNotValid'; - const INVALID = 'sitemapPriorityInvalid'; + const NOT_VALID = 'invalidSitemapPriority'; /** * Validation failure message template definitions @@ -51,8 +50,7 @@ class Zend_Validate_Sitemap_Priority extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_VALID => "'%value%' is no valid sitemap priority", - self::INVALID => "Invalid type given, the value should be a integer, a float or a numeric string", + self::NOT_VALID => "'%value%' is not a valid sitemap priority", ); /** @@ -65,18 +63,13 @@ class Zend_Validate_Sitemap_Priority extends Zend_Validate_Abstract */ public function isValid($value) { - if (!is_numeric($value)) { - $this->_error(self::INVALID); - return false; - } - $this->_setValue($value); - $value = (float) $value; - if ($value < 0 || $value > 1) { - $this->_error(self::NOT_VALID); + + if (!is_numeric($value)) { return false; } - return true; + $value = (float)$value; + return $value >= 0 && $value <= 1; } } diff --git a/libs/Zend/Validate/StringLength.php b/libs/Zend/Validate/StringLength.php index c9362ace22..7ec9125f92 100644 --- a/libs/Zend/Validate/StringLength.php +++ b/libs/Zend/Validate/StringLength.php @@ -14,20 +14,20 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: StringLength.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: StringLength.php 16223 2009-06-21 20:04:53Z thomas $ */ /** * @see Zend_Validate_Abstract */ -// require_once 'Zend/Validate/Abstract.php'; +require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 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 @@ -42,7 +42,7 @@ class Zend_Validate_StringLength extends Zend_Validate_Abstract protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be a string", self::TOO_SHORT => "'%value%' is less than %min% characters long", - self::TOO_LONG => "'%value%' is more than %max% characters long", + self::TOO_LONG => "'%value%' is greater than %max% characters long" ); /** @@ -79,39 +79,15 @@ class Zend_Validate_StringLength extends Zend_Validate_Abstract /** * Sets validator options * - * @param integer|array|Zend_Config $options + * @param integer $min + * @param integer $max * @return void */ - public function __construct($options = array()) + public function __construct($min = 0, $max = null, $encoding = null) { - if ($options instanceof Zend_Config) { - $options = $options->toArray(); - } else if (!is_array($options)) { - $options = func_get_args(); - $temp['min'] = array_shift($options); - if (!empty($options)) { - $temp['max'] = array_shift($options); - } - - if (!empty($options)) { - $temp['encoding'] = array_shift($options); - } - - $options = $temp; - } - - if (!array_key_exists('min', $options)) { - $options['min'] = 0; - } - - $this->setMin($options['min']); - if (array_key_exists('max', $options)) { - $this->setMax($options['max']); - } - - if (array_key_exists('encoding', $options)) { - $this->setEncoding($options['encoding']); - } + $this->setMin($min); + $this->setMax($max); + $this->setEncoding($encoding); } /** @@ -137,7 +113,7 @@ class Zend_Validate_StringLength extends Zend_Validate_Abstract /** * @see Zend_Validate_Exception */ - // require_once 'Zend/Validate/Exception.php'; + 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"); } @@ -170,7 +146,7 @@ class Zend_Validate_StringLength extends Zend_Validate_Abstract /** * @see Zend_Validate_Exception */ - // require_once 'Zend/Validate/Exception.php'; + 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 { @@ -202,7 +178,7 @@ class Zend_Validate_StringLength extends Zend_Validate_Abstract $orig = iconv_get_encoding('internal_encoding'); $result = iconv_set_encoding('internal_encoding', $encoding); if (!$result) { - // require_once 'Zend/Validate/Exception.php'; + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception('Given encoding not supported on this OS!'); } |