diff options
Diffstat (limited to 'libs/Zend/Validate')
87 files changed, 4927 insertions, 813 deletions
diff --git a/libs/Zend/Validate/Abstract.php b/libs/Zend/Validate/Abstract.php index 3107360619..b59478e97d 100644 --- a/libs/Zend/Validate/Abstract.php +++ b/libs/Zend/Validate/Abstract.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Abstract.php 18688 2009-10-25 16:08:24Z thomas $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -27,7 +27,7 @@ require_once 'Zend/Validate/Interface.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Abstract implements Zend_Validate_Interface @@ -251,11 +251,11 @@ abstract class Zend_Validate_Abstract implements Zend_Validate_Interface } /** - * @param string $messageKey OPTIONAL + * @param string $messageKey * @param string $value OPTIONAL * @return void */ - protected function _error($messageKey = null, $value = null) + protected function _error($messageKey, $value = null) { if ($messageKey === null) { $keys = array_keys($this->_messageTemplates); diff --git a/libs/Zend/Validate/Alnum.php b/libs/Zend/Validate/Alnum.php index c2f2f46642..d222a368f3 100644 --- a/libs/Zend/Validate/Alnum.php +++ b/libs/Zend/Validate/Alnum.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Alnum.php 17467 2009-08-08 18:06:55Z thomas $ + * @version $Id: Alnum.php 20442 2010-01-20 15:15:40Z matthew $ */ /** @@ -27,20 +27,20 @@ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Alnum extends Zend_Validate_Abstract { const INVALID = 'alnumInvalid'; const NOT_ALNUM = 'notAlnum'; - const STRING_EMPTY = 'stringEmpty'; + const STRING_EMPTY = 'alnumStringEmpty'; /** * Whether to allow white space characters; off by default * * @var boolean - * @depreciated + * @deprecated */ public $allowWhiteSpace; @@ -58,18 +58,30 @@ 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%' has not only alphabetic and digit characters", - self::STRING_EMPTY => "'%value%' is an empty string" + self::NOT_ALNUM => "'%value%' contains characters which are non alphabetic and no digits", + self::STRING_EMPTY => "'%value%' is an empty string", ); /** * Sets default option values for this instance * - * @param boolean $allowWhiteSpace + * @param boolean|Zend_Config $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; } diff --git a/libs/Zend/Validate/Alpha.php b/libs/Zend/Validate/Alpha.php index ce1f01872f..5474177744 100644 --- a/libs/Zend/Validate/Alpha.php +++ b/libs/Zend/Validate/Alpha.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Alpha.php 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: Alpha.php 20442 2010-01-20 15:15:40Z matthew $ */ /** @@ -27,20 +27,20 @@ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Alpha extends Zend_Validate_Abstract { const INVALID = 'alphaInvalid'; const NOT_ALPHA = 'notAlpha'; - const STRING_EMPTY = 'stringEmpty'; + const STRING_EMPTY = 'alphaStringEmpty'; /** * Whether to allow white space characters; off by default * * @var boolean - * @depreciated + * @deprecated */ public $allowWhiteSpace; @@ -58,18 +58,30 @@ 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%' has not only alphabetic characters", + self::NOT_ALPHA => "'%value%' contains non alphabetic characters", self::STRING_EMPTY => "'%value%' is an empty string" ); /** * Sets default option values for this instance * - * @param boolean $allowWhiteSpace + * @param boolean|Zend_Config $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; } diff --git a/libs/Zend/Validate/Barcode.php b/libs/Zend/Validate/Barcode.php index 374a9e5449..933999a504 100644 --- a/libs/Zend/Validate/Barcode.php +++ b/libs/Zend/Validate/Barcode.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Barcode.php 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: Barcode.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -25,59 +25,153 @@ require_once 'Zend/Validate/Abstract.php'; /** + * @see Zend_Loader + */ +require_once 'Zend/Loader.php'; + +/** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 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' + ); + /** - * Barcode validator + * Length for the set subtype * - * @var Zend_Validate_Abstract + * @var integer */ - protected $_barcodeValidator; + protected $_length; + + /** + * Barcode adapter + * + * @var Zend_Validate_Barcode_BarcodeAdapter + */ + protected $_adapter; /** * Generates the standard validator object * - * @param string $barcodeType - Barcode validator to use + * @param string|Zend_Config| + * Zend_Validate_Barcode_BarcodeAdapter $adapter Barcode adapter to use * @return void * @throws Zend_Validate_Exception */ - public function __construct($barcodeType) + 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() { - $this->setType($barcodeType); + return $this->_adapter; } /** - * Sets a new barcode validator + * Sets a new barcode adapter * - * @param string $barcodeType - Barcode validator to use + * @param string|Zend_Validate_Barcode $adapter Barcode adapter to use + * @param array $options Options for this adapter * @return void * @throws Zend_Validate_Exception */ - public function setType($barcodeType) + public function setAdapter($adapter, $options = null) { - 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; + $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->_barcodeValidator = new $class; + $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" + ); + } + + 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; } /** @@ -90,6 +184,34 @@ class Zend_Validate_Barcode extends Zend_Validate_Abstract */ public function isValid($value) { - return call_user_func(array($this->_barcodeValidator, 'isValid'), $value); + if (!is_string($value)) { + $this->_error(self::INVALID); + return false; + } + + $this->_value = (string) $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; } -} +}
\ No newline at end of file diff --git a/libs/Zend/Validate/Barcode/AdapterAbstract.php b/libs/Zend/Validate/Barcode/AdapterAbstract.php new file mode 100644 index 0000000000..043189e6c2 --- /dev/null +++ b/libs/Zend/Validate/Barcode/AdapterAbstract.php @@ -0,0 +1,315 @@ +<?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 new file mode 100644 index 0000000000..325c6048f3 --- /dev/null +++ b/libs/Zend/Validate/Barcode/AdapterInterface.php @@ -0,0 +1,68 @@ +<?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 new file mode 100644 index 0000000000..efb5a395c7 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Code25.php @@ -0,0 +1,64 @@ +<?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 new file mode 100644 index 0000000000..7e5a8d919b --- /dev/null +++ b/libs/Zend/Validate/Barcode/Code25interleaved.php @@ -0,0 +1,64 @@ +<?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 new file mode 100644 index 0000000000..858084fe25 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Code39.php @@ -0,0 +1,100 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..5c1d65ee64 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Code39ext.php @@ -0,0 +1,58 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..deb5183d43 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Code93.php @@ -0,0 +1,120 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..740d485c4a --- /dev/null +++ b/libs/Zend/Validate/Barcode/Code93ext.php @@ -0,0 +1,58 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..56a2384be2 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Ean12.php @@ -0,0 +1,52 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 068809248c..b7e52f4c13 100644 --- a/libs/Zend/Validate/Barcode/Ean13.php +++ b/libs/Zend/Validate/Barcode/Ean13.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,96 +14,39 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: Ean13.php 20096 2010-01-06 02:05:09Z bkarwin $ */ - /** - * @see Zend_Validate_Abstract + * @see Zend_Validate_Barcode_AdapterAbstract */ -require_once 'Zend/Validate/Abstract.php'; - +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Ean13 extends Zend_Validate_Abstract +class Zend_Validate_Barcode_Ean13 extends Zend_Validate_Barcode_AdapterAbstract { /** - * 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 + * Allowed barcode lengths + * @var integer */ - const INVALID_LENGTH = 'invalidLength'; + protected $_length = 13; /** - * Validation failure message key for when the value - * does not only contain numeric characters + * Allowed barcode characters + * @var string */ - const NOT_NUMERIC = 'ean13NotNumeric'; + protected $_characters = '0123456789'; /** - * Validation failure message template definitions - * - * @var array + * Checksum function + * @var string */ - 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; - } + protected $_checksum = '_gtin'; } diff --git a/libs/Zend/Validate/Barcode/Ean14.php b/libs/Zend/Validate/Barcode/Ean14.php new file mode 100644 index 0000000000..93d46d8c4f --- /dev/null +++ b/libs/Zend/Validate/Barcode/Ean14.php @@ -0,0 +1,52 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..93398dd916 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Ean18.php @@ -0,0 +1,52 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..deab558ea4 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Ean2.php @@ -0,0 +1,58 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..af6e493241 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Ean5.php @@ -0,0 +1,58 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..c87af039fd --- /dev/null +++ b/libs/Zend/Validate/Barcode/Ean8.php @@ -0,0 +1,69 @@ +<?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 new file mode 100644 index 0000000000..8915c4ec4c --- /dev/null +++ b/libs/Zend/Validate/Barcode/Gtin12.php @@ -0,0 +1,52 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..0719b31eb6 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Gtin13.php @@ -0,0 +1,52 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..d1dad51069 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Gtin14.php @@ -0,0 +1,52 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..c0119a5cd9 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Identcode.php @@ -0,0 +1,52 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..4c266db8a4 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Intelligentmail.php @@ -0,0 +1,58 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..be629920e7 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Issn.php @@ -0,0 +1,119 @@ +<?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 new file mode 100644 index 0000000000..d207a314c8 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Itf14.php @@ -0,0 +1,52 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..551ded0649 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Leitcode.php @@ -0,0 +1,52 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..72608fa38a --- /dev/null +++ b/libs/Zend/Validate/Barcode/Planet.php @@ -0,0 +1,52 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..c638dc7314 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Postnet.php @@ -0,0 +1,52 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..8c4b733b5b --- /dev/null +++ b/libs/Zend/Validate/Barcode/Royalmail.php @@ -0,0 +1,121 @@ +<?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 new file mode 100644 index 0000000000..50dd820793 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Sscc.php @@ -0,0 +1,52 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 deleted file mode 100644 index cf33f31fab..0000000000 --- a/libs/Zend/Validate/Barcode/UpcA.php +++ /dev/null @@ -1,103 +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-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 new file mode 100644 index 0000000000..449c78dd37 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Upca.php @@ -0,0 +1,52 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-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 new file mode 100644 index 0000000000..f4ccc74eb6 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Upce.php @@ -0,0 +1,69 @@ +<?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 b9fd7c2dc6..332d7cb1e2 100644 --- a/libs/Zend/Validate/Between.php +++ b/libs/Zend/Validate/Between.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,22 +14,20 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Between.php 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: Between.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-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Between extends Zend_Validate_Abstract @@ -91,17 +88,44 @@ 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 mixed $min - * @param mixed $max - * @param boolean $inclusive + * @param array|Zend_Config $options * @return void */ - public function __construct($min, $max, $inclusive = true) + public function __construct($options) { - $this->setMin($min) - ->setMax($max) - ->setInclusive($inclusive); + 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']); } /** diff --git a/libs/Zend/Validate/Callback.php b/libs/Zend/Validate/Callback.php new file mode 100644 index 0000000000..7dbade86a7 --- /dev/null +++ b/libs/Zend/Validate/Callback.php @@ -0,0 +1,174 @@ +<?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 489573c48d..71f0f83bf3 100644 --- a/libs/Zend/Validate/Ccnum.php +++ b/libs/Zend/Validate/Ccnum.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,22 +14,20 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Ccnum.php 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: Ccnum.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-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Ccnum extends Zend_Validate_Abstract @@ -62,6 +59,11 @@ 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 * @@ -107,5 +109,4 @@ class Zend_Validate_Ccnum extends Zend_Validate_Abstract return true; } - } diff --git a/libs/Zend/Validate/CreditCard.php b/libs/Zend/Validate/CreditCard.php new file mode 100644 index 0000000000..127e2f2e63 --- /dev/null +++ b/libs/Zend/Validate/CreditCard.php @@ -0,0 +1,315 @@ +<?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 20358 2010-01-17 19:03:49Z 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(); + $found = false; + foreach ($types as $type) { + if (in_array($length, $this->_cardLength[$type])) { + foreach ($this->_cardType[$type] as $prefix) { + if (substr($value, 0, strlen($prefix)) == $prefix) { + $found = true; + break; + } + } + } + } + + if ($found == false) { + if (!in_array($length, $this->_cardLength[$type])) { + $this->_error(self::LENGTH, $value); + return false; + } else { + $this->_error(self::PREFIX, $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 5dbcc6d702..993f99cb51 100644 --- a/libs/Zend/Validate/Date.php +++ b/libs/Zend/Validate/Date.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Date.php 17696 2009-08-20 20:12:33Z thomas $ + * @version $Id: Date.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -27,14 +27,13 @@ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Date extends Zend_Validate_Abstract { const INVALID = 'dateInvalid'; - const NOT_YYYY_MM_DD = 'dateNotYYYY-MM-DD'; - const INVALID_DATE = 'dateInvalidDate'; + const INVALID_DATE = 'dateInvalidDate'; const FALSEFORMAT = 'dateFalseFormat'; /** @@ -44,9 +43,15 @@ 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 given date format" + self::FALSEFORMAT => "'%value%' does not fit the date format '%format%'", + ); + + /** + * @var array + */ + protected $_messageVariables = array( + 'format' => '_format' ); /** @@ -66,22 +71,36 @@ class Zend_Validate_Date extends Zend_Validate_Abstract /** * Sets validator options * - * @param string $format OPTIONAL - * @param string|Zend_Locale $locale OPTIONAL + * @param string|Zend_Config $options OPTIONAL * @return void */ - public function __construct($format = null, $locale = null) + public function __construct($options = array()) { - $this->setFormat($format); - if ($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'; if (Zend_Registry::isRegistered('Zend_Locale')) { - $locale = Zend_Registry::get('Zend_Locale'); + $options['locale'] = Zend_Registry::get('Zend_Locale'); } } - if ($locale !== null) { - $this->setLocale($locale); + if (array_key_exists('locale', $options)) { + $this->setLocale($options['locale']); } } @@ -163,7 +182,9 @@ class Zend_Validate_Date extends Zend_Validate_Abstract } } else { if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) { - $this->_error(self::NOT_YYYY_MM_DD); + $this->_format = 'yyyy-MM-dd'; + $this->_error(self::FALSEFORMAT); + $this->_format = null; return false; } diff --git a/libs/Zend/Validate/Db/Abstract.php b/libs/Zend/Validate/Db/Abstract.php index de5a863ea8..c1d2a98b3f 100644 --- a/libs/Zend/Validate/Db/Abstract.php +++ b/libs/Zend/Validate/Db/Abstract.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Abstract.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Abstract.php 20412 2010-01-19 07:02:01Z thomas $ */ /** @@ -31,7 +30,7 @@ require_once 'Zend/Validate/Abstract.php'; * @category Zend * @package Zend_Validate * @uses Zend_Validate_Abstract - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Abstract extends Zend_Validate_Abstract @@ -45,8 +44,10 @@ abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract /** * @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 @@ -82,26 +83,175 @@ abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract * 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. + * 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($table, $field, $exclude = null, Zend_Db_Adapter_Abstract $adapter = null) + public function __construct($options) { - if ($adapter !== null) { - $this->_adapter = $adapter; + 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; } - $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; + 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']); + } + } + + /** + * 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; } /** diff --git a/libs/Zend/Validate/Db/NoRecordExists.php b/libs/Zend/Validate/Db/NoRecordExists.php index e9c0db49a8..98dc59b8a2 100644 --- a/libs/Zend/Validate/Db/NoRecordExists.php +++ b/libs/Zend/Validate/Db/NoRecordExists.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: NoRecordExists.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: NoRecordExists.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -31,7 +30,7 @@ require_once 'Zend/Validate/Db/Abstract.php'; * @category Zend * @package Zend_Validate * @uses Zend_Validate_Db_Abstract - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_NoRecordExists extends Zend_Validate_Db_Abstract diff --git a/libs/Zend/Validate/Db/RecordExists.php b/libs/Zend/Validate/Db/RecordExists.php index 22f39bc6a0..4a9122ad02 100644 --- a/libs/Zend/Validate/Db/RecordExists.php +++ b/libs/Zend/Validate/Db/RecordExists.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,12 +14,11 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: RecordExists.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: RecordExists.php 20096 2010-01-06 02:05:09Z bkarwin $ */ - /** * @see Zend_Validate_Db_Abstract */ @@ -32,7 +30,7 @@ require_once 'Zend/Validate/Db/Abstract.php'; * @category Zend * @package Zend_Validate * @uses Zend_Validate_Db_Abstract - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_RecordExists extends Zend_Validate_Db_Abstract diff --git a/libs/Zend/Validate/Digits.php b/libs/Zend/Validate/Digits.php index 12e6c4e454..d6528dde01 100644 --- a/libs/Zend/Validate/Digits.php +++ b/libs/Zend/Validate/Digits.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,28 +14,26 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Digits.php 16933 2009-07-21 20:24:35Z matthew $ + * @version $Id: Digits.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-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Digits extends Zend_Validate_Abstract { const NOT_DIGITS = 'notDigits'; - const STRING_EMPTY = 'stringEmpty'; + const STRING_EMPTY = 'digitsStringEmpty'; const INVALID = 'digitsInvalid'; /** @@ -91,5 +88,4 @@ 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 4948bb83f3..388fe6b55c 100644 --- a/libs/Zend/Validate/EmailAddress.php +++ b/libs/Zend/Validate/EmailAddress.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: EmailAddress.php 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: EmailAddress.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Validate/Hostname.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_EmailAddress extends Zend_Validate_Abstract @@ -41,6 +41,7 @@ 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'; @@ -51,37 +52,47 @@ 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 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_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_MX_RECORD => "'%hostname%' does not appear to have a valid MX record for the email address '%value%'", - self::DOT_ATOM => "'%localPart%' not matched against dot-atom format", - self::QUOTED_STRING => "'%localPart%' not matched against quoted-string format", - self::INVALID_LOCAL_PART => "'%localPart%' is not a valid local part for email address '%value%'", - self::LENGTH_EXCEEDED => "'%value%' exceeds the allowed length" + 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 $_messageVariables = array( - 'hostname' => '_hostname', - 'localPart' => '_localPart' + 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' ); /** - * Local object for validating the hostname part of an email address - * - * @var Zend_Validate_Hostname - * @depreciated - */ - public $hostnameValidator; - - /** - * Whether we check for a valid MX record via DNS - * - * @var boolean + * @var array */ - protected $_validateMx = false; + protected $_messageVariables = array( + 'hostname' => '_hostname', + 'localPart' => '_localPart' + ); /** * @var string @@ -94,21 +105,118 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract protected $_localPart; /** + * Internal options array + */ + protected $_options = array( + 'mx' => false, + 'deep' => false, + 'domain' => true, + 'allow' => Zend_Validate_Hostname::ALLOW_DNS, + 'hostname' => null + ); + + /** * 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 + * 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 integer $allow OPTIONAL - * @param bool $validateMx OPTIONAL - * @param Zend_Validate_Hostname $hostnameValidator OPTIONAL + * @param array|Zend_Config $options OPTIONAL * @return void */ - public function __construct($allow = Zend_Validate_Hostname::ALLOW_DNS, $validateMx = false, Zend_Validate_Hostname $hostnameValidator = null) + public function __construct($options = array()) { - $this->setValidateMx($validateMx); - $this->setHostnameValidator($hostnameValidator, $allow); + 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); + } + + /** + * Returns all set Options + * + * @return array + */ + public function getOptions() + { + return $this->_options; + } + + /** + * Set options for the email validator + * + * @param array $options + * @return Zend_Validate_EmailAddress fluid interface + */ + 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; + } + + /** + * Sets the validation failure message template for a particular key + * Adds the ability to set messages to the attached hostname validator + * + * @param string $messageString + * @param string $messageKey OPTIONAL + * @return Zend_Validate_Abstract Provides a fluent interface + * @throws Zend_Validate_Exception + */ + public function setMessage($messageString, $messageKey = null) + { + $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; } /** @@ -118,7 +226,7 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract */ public function getHostnameValidator() { - return $this->hostnameValidator; + return $this->_options['hostname']; } /** @@ -128,14 +236,17 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract */ public function setHostnameValidator(Zend_Validate_Hostname $hostnameValidator = null, $allow = Zend_Validate_Hostname::ALLOW_DNS) { - if ($hostnameValidator === null) { + if (!$hostnameValidator) { $hostnameValidator = new Zend_Validate_Hostname($allow); } - $this->hostnameValidator = $hostnameValidator; + + $this->_options['hostname'] = $hostnameValidator; + $this->_options['allow'] = $allow; + return $this; } /** - * Whether MX checking via dns_get_mx is supported or not + * Whether MX checking via getmxrr is supported or not * * This currently only works on UNIX systems * @@ -143,7 +254,17 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract */ public function validateMxSupported() { - return function_exists('dns_get_mx'); + return function_exists('getmxrr'); + } + + /** + * Returns the set validateMx option + * + * @return boolean + */ + public function getValidateMx() + { + return $this->_options['mx']; } /** @@ -151,11 +272,235 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract * * This only applies when DNS hostnames are validated * - * @param boolean $allowed Set allowed to true to validate for MX records, and false to not validate them + * @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 */ - public function setValidateMx($allowed) + public function setDeepMxCheck($deep) { - $this->_validateMx = (bool) $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->_binaryToIp(str_pad(substr($binaryHost, 0, $host[1]), 32, 0)), + 'broadcast' => (int)$this->_binaryToIp(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() + { + $result = true; + $mxHosts = array(); + getmxrr($this->_hostname, $mxHosts); + 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; } /** @@ -176,9 +521,8 @@ 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 '..' @@ -197,68 +541,19 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract } // Match hostname part - $hostnameResult = $this->hostnameValidator->setTranslator($this->getTranslator()) - ->isValid($this->_hostname); - if (!$hostnameResult) { - $this->_error(self::INVALID_HOSTNAME); - - // Get messages and errors from hostnameValidator - foreach ($this->hostnameValidator->getMessages() as $code => $message) { - $this->_messages[$code] = $message; - } - foreach ($this->hostnameValidator->getErrors() as $error) { - $this->_errors[] = $error; - } - } else if ($this->_validateMx) { - // MX check on hostname via dns_get_record() - if ($this->validateMxSupported()) { - $result = dns_get_mx($this->_hostname, $mxHosts); - if (count($mxHosts) < 1) { - $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'); - } + if ($this->_options['domain']) { + $hostname = $this->_validateHostnamePart(); } - // First try to match the local part on the common dot-atom format - $localResult = false; - - // Dot-atom characters are: 1*atext *("." 1*atext) - // atext: ALPHA / DIGIT / and "!", "#", "$", "%", "&", "'", "*", - // "+", "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~" - $atext = 'a-zA-Z0-9\x21\x23\x24\x25\x26\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b\x7c\x7d\x7e'; - if (preg_match('/^[' . $atext . ']+(\x2e+[' . $atext . ']+)*$/', $this->_localPart)) { - $localResult = true; - } else { - // Try quoted string format + $local = $this->_validateLocalPart(); - // Quoted-string characters are: DQUOTE *([FWS] qtext/quoted-pair) [FWS] DQUOTE - // qtext: Non white space controls, and the rest of the US-ASCII characters not - // including "\" or the quote character - $noWsCtl = '\x01-\x08\x0b\x0c\x0e-\x1f\x7f'; - $qtext = $noWsCtl . '\x21\x23-\x5b\x5d-\x7e'; - $ws = '\x20\x09'; - if (preg_match('/^\x22([' . $ws . $qtext . '])*[$ws]?\x22$/', $this->_localPart)) { - $localResult = true; - } else { - $this->_error(self::DOT_ATOM); - $this->_error(self::QUOTED_STRING); - $this->_error(self::INVALID_LOCAL_PART); + // If both parts valid, return true + if ($local && $length) { + if (($this->_options['domain'] && $hostname) || !$this->_options['domain']) { + return true; } } - // If both parts valid, return true - if ($localResult && $hostnameResult && $length) { - return true; - } else { - return false; - } + return false; } } diff --git a/libs/Zend/Validate/Exception.php b/libs/Zend/Validate/Exception.php index d6b646f1cd..fa875e14ed 100644 --- a/libs/Zend/Validate/Exception.php +++ b/libs/Zend/Validate/Exception.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,22 +14,20 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Exception.php 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ - /** * @see Zend_Exception */ require_once 'Zend/Exception.php'; - /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Exception extends Zend_Exception diff --git a/libs/Zend/Validate/File/Count.php b/libs/Zend/Validate/File/Count.php index f2dfac7413..e7519b0d63 100644 --- a/libs/Zend/Validate/File/Count.php +++ b/libs/Zend/Validate/File/Count.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Count.php 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: Count.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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_MUCH = 'fileCountTooMuch'; - const TOO_LESS = 'fileCountTooLess'; + const TOO_MANY = 'fileCountTooMany'; + const TOO_FEW = 'fileCountTooFew'; /**#@-*/ /** * @var array Error message templates */ protected $_messageTemplates = array( - 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" + 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", ); /** @@ -115,8 +115,6 @@ class Zend_Validate_File_Count 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 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); } @@ -243,14 +241,22 @@ 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']; + } + $this->addFile($value); $this->_count = count($this->_files); if (($this->_max !== null) && ($this->_count > $this->_max)) { - return $this->_throw($file, self::TOO_MUCH); + return $this->_throw($file, self::TOO_MANY); } if (($this->_min !== null) && ($this->_count < $this->_min)) { - return $this->_throw($file, self::TOO_LESS); + return $this->_throw($file, self::TOO_FEW); } return true; diff --git a/libs/Zend/Validate/File/Crc32.php b/libs/Zend/Validate/File/Crc32.php index fd46d81b6b..e7c06d6035 100644 --- a/libs/Zend/Validate/File/Crc32.php +++ b/libs/Zend/Validate/File/Crc32.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Crc32.php 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: Crc32.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/Hash.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 => "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" + 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", ); /** diff --git a/libs/Zend/Validate/File/ExcludeExtension.php b/libs/Zend/Validate/File/ExcludeExtension.php index 74264de98c..b31e372747 100644 --- a/libs/Zend/Validate/File/ExcludeExtension.php +++ b/libs/Zend/Validate/File/ExcludeExtension.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: ExcludeExtension.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: ExcludeExtension.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/Extension.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 => "The file '%value%' has a false extension", - self::NOT_FOUND => "The file '%value%' was not found" + self::FALSE_EXTENSION => "File '%value%' has a false extension", + self::NOT_FOUND => "File '%value%' could not be found", ); /** diff --git a/libs/Zend/Validate/File/ExcludeMimeType.php b/libs/Zend/Validate/File/ExcludeMimeType.php index 4984b79cfb..22f74fba8b 100644 --- a/libs/Zend/Validate/File/ExcludeMimeType.php +++ b/libs/Zend/Validate/File/ExcludeMimeType.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: ExcludeMimeType.php 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: ExcludeMimeType.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/MimeType.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_File_ExcludeMimeType extends Zend_Validate_File_MimeType diff --git a/libs/Zend/Validate/File/Exists.php b/libs/Zend/Validate/File/Exists.php index 835b4c2c70..86a21780fb 100644 --- a/libs/Zend/Validate/File/Exists.php +++ b/libs/Zend/Validate/File/Exists.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Exists.php 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: Exists.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 => "The file '%value%' does not exist" + self::DOES_NOT_EXIST => "File '%value%' does not exist", ); /** diff --git a/libs/Zend/Validate/File/Extension.php b/libs/Zend/Validate/File/Extension.php index 58ab0b21af..021b5e03bb 100644 --- a/libs/Zend/Validate/File/Extension.php +++ b/libs/Zend/Validate/File/Extension.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Extension.php 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: Extension.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 => "The file '%value%' has a false extension", - self::NOT_FOUND => "The file '%value%' was not found" + self::FALSE_EXTENSION => "File '%value%' has a false extension", + self::NOT_FOUND => "File '%value%' could not be found", ); /** @@ -81,8 +81,6 @@ 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); } diff --git a/libs/Zend/Validate/File/FilesSize.php b/libs/Zend/Validate/File/FilesSize.php index 167304b771..05c660b81b 100644 --- a/libs/Zend/Validate/File/FilesSize.php +++ b/libs/Zend/Validate/File/FilesSize.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: FilesSize.php 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: FilesSize.php 20455 2010-01-20 22:54:18Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/Size.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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", ); /** @@ -81,9 +81,6 @@ class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size } 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); @@ -131,12 +128,14 @@ class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size // limited to 2GB files $size += @filesize($files); - $this->_setSize($size); + $this->_size = $size; if (($max !== null) && ($max < $size)) { if ($this->useByteString()) { - $this->setMax($this->_toByteString($max)); + $this->_max = $this->_toByteString($max); + $this->_size = $this->_toByteString($size); $this->_throw($file, self::TOO_BIG); - $this->setMax($max); + $this->_max = $max; + $this->_size = $size; } else { $this->_throw($file, self::TOO_BIG); } @@ -146,9 +145,11 @@ 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->setMin($this->_toByteString($min)); + $this->_min = $this->_toByteString($min); + $this->_size = $this->_toByteString($size); $this->_throw($file, self::TOO_SMALL); - $this->setMin($min); + $this->_min = $min; + $this->_size = $size; } else { $this->_throw($file, self::TOO_SMALL); } diff --git a/libs/Zend/Validate/File/Hash.php b/libs/Zend/Validate/File/Hash.php index d2e8c2c645..2b20cac699 100644 --- a/libs/Zend/Validate/File/Hash.php +++ b/libs/Zend/Validate/File/Hash.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Hash.php 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: Hash.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 => "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" + 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" ); /** @@ -75,8 +75,6 @@ class Zend_Validate_File_Hash 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 constructor options are deprecated in favor of a single options array', E_USER_NOTICE); $options['algorithm'] = func_get_arg(1); } diff --git a/libs/Zend/Validate/File/ImageSize.php b/libs/Zend/Validate/File/ImageSize.php index c01ec97341..0d8a4fa74e 100644 --- a/libs/Zend/Validate/File/ImageSize.php +++ b/libs/Zend/Validate/File/ImageSize.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: ImageSize.php 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: ImageSize.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 => "The image '%value%' can not be read" + self::NOT_READABLE => "File '%value%' can not be read", ); /** @@ -127,8 +127,6 @@ 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); } diff --git a/libs/Zend/Validate/File/IsCompressed.php b/libs/Zend/Validate/File/IsCompressed.php index 3254d57341..d2b8a25430 100644 --- a/libs/Zend/Validate/File/IsCompressed.php +++ b/libs/Zend/Validate/File/IsCompressed.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: IsCompressed.php 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: IsCompressed.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/MimeType.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 => "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" + 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", ); /** @@ -60,27 +60,74 @@ 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' - ); } - $this->setMimeType($mimetype); + $temp = array(); + $default = 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' + ); + + 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; } } diff --git a/libs/Zend/Validate/File/IsImage.php b/libs/Zend/Validate/File/IsImage.php index 3904af1f90..77756277f0 100644 --- a/libs/Zend/Validate/File/IsImage.php +++ b/libs/Zend/Validate/File/IsImage.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: IsImage.php 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: IsImage.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/MimeType.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 => "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" + self::FALSE_TYPE => "File '%value%' is no image, '%type%' detected", + self::NOT_DETECTED => "The mimetype of file '%value%' could not been detected", + self::NOT_READABLE => "File '%value%' can not be read", ); /** @@ -60,31 +60,78 @@ 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' - ); } - $this->setMimeType($mimetype); + $temp = array(); + $default = 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' + ); + + 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; } } diff --git a/libs/Zend/Validate/File/Md5.php b/libs/Zend/Validate/File/Md5.php index cfbd83fb53..80fed0bd26 100644 --- a/libs/Zend/Validate/File/Md5.php +++ b/libs/Zend/Validate/File/Md5.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Md5.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Md5.php 20442 2010-01-20 15:15:40Z matthew $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/Hash.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 => "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" + 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", ); /** @@ -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 (Depreciated) Algorithm to use, fixed to md5 + * @param string $algorithm (Deprecated) Algorithm to use, fixed to md5 * @return Zend_Validate_File_Hash Provides a fluent interface */ public function addHash($options) diff --git a/libs/Zend/Validate/File/MimeType.php b/libs/Zend/Validate/File/MimeType.php index 2bf372c4fc..a4b4ec58aa 100644 --- a/libs/Zend/Validate/File/MimeType.php +++ b/libs/Zend/Validate/File/MimeType.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: MimeType.php 18513 2009-10-12 16:17:35Z matthew $ + * @version $Id: MimeType.php 20505 2010-01-21 21:40:23Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 => "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" + 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", ); /** @@ -123,10 +123,12 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract if (isset($mimetype['magicfile'])) { $this->setMagicFile($mimetype['magicfile']); + unset($mimetype['magicfile']); } if (isset($mimetype['headerCheck'])) { - $this->enableHeaderCheck(true); + $this->enableHeaderCheck($mimetype['headerCheck']); + unset($mimetype['headerCheck']); } $this->setMimeType($mimetype); @@ -139,14 +141,20 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract */ public function getMagicFile() { - if (null === $this->_magicfile && empty($_ENV['MAGIC'])) { - foreach ($this->_magicFiles as $file) { - if (file_exists($file)) { - $this->setMagicFile($file); - break; + if (null === $this->_magicfile) { + if (!empty($_ENV['MAGIC'])) { + $this->setMagicFile($_ENV['MAGIC']); + } elseif (!(@ini_get("safe_mode") == 'On' || @ini_get("safe_mode") === 1)) { + foreach ($this->_magicFiles as $file) { + // supressing errors which are thrown due to openbase_dir restrictions + if (@file_exists($file)) { + $this->setMagicFile($file); + break; + } } } } + return $this->_magicfile; } @@ -306,12 +314,13 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract unset($mime); } - if (empty($this->_type)) { - if (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) { + if (empty($this->_type) && + (function_exists('mime_content_type') && ini_get('mime_magic.magicfile'))) { $this->_type = mime_content_type($value); - } elseif ($this->_headerCheck) { - $this->_type = $file['type']; - } + } + + if (empty($this->_type) && $this->_headerCheck) { + $this->_type = $file['type']; } if (empty($this->_type)) { diff --git a/libs/Zend/Validate/File/NotExists.php b/libs/Zend/Validate/File/NotExists.php index 0cc3c87ac9..87ebb827b4 100644 --- a/libs/Zend/Validate/File/NotExists.php +++ b/libs/Zend/Validate/File/NotExists.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: NotExists.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: NotExists.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/Exists.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 => "The file '%value%' does exist" + self::DOES_EXIST => "File '%value%' exists", ); /** diff --git a/libs/Zend/Validate/File/Sha1.php b/libs/Zend/Validate/File/Sha1.php index 9dd4418d71..2157bfb26c 100644 --- a/libs/Zend/Validate/File/Sha1.php +++ b/libs/Zend/Validate/File/Sha1.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Sha1.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Sha1.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/Hash.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 => "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" + 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", ); /** diff --git a/libs/Zend/Validate/File/Size.php b/libs/Zend/Validate/File/Size.php index 4c41178966..bfd02aa80b 100644 --- a/libs/Zend/Validate/File/Size.php +++ b/libs/Zend/Validate/File/Size.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Size.php 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: Size.php 20455 2010-01-20 22:54:18Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 => "The file '%value%' could not be found" + self::NOT_FOUND => "File '%value%' could not be found", ); /** @@ -112,8 +112,6 @@ class Zend_Validate_File_Size 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 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); @@ -282,7 +280,8 @@ class Zend_Validate_File_Size extends Zend_Validate_Abstract } // limited to 4GB files - $size = sprintf("%u", @filesize($value)); + $size = sprintf("%u", @filesize($value)); + $this->_size = $size; // 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 fd1bdfe754..85f408c735 100644 --- a/libs/Zend/Validate/File/Upload.php +++ b/libs/Zend/Validate/File/Upload.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Upload.php 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: Upload.php 20431 2010-01-19 21:36:05Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 => "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%'" + 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%'" ); /** diff --git a/libs/Zend/Validate/File/WordCount.php b/libs/Zend/Validate/File/WordCount.php index b5249532d3..9936cb662f 100644 --- a/libs/Zend/Validate/File/WordCount.php +++ b/libs/Zend/Validate/File/WordCount.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: WordCount.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: WordCount.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/Count.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 => "The file '%value%' could not be found" + self::NOT_FOUND => "File '%value%' could not be found", ); /** diff --git a/libs/Zend/Validate/Float.php b/libs/Zend/Validate/Float.php index bfa5e62c14..c855aeaf03 100644 --- a/libs/Zend/Validate/Float.php +++ b/libs/Zend/Validate/Float.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Float.php 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: Float.php 20532 2010-01-22 20:18:23Z thomas $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Locale/Format.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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,10 +53,29 @@ class Zend_Validate_Float extends Zend_Validate_Abstract /** * Constructor for the float validator * - * @param string|Zend_Locale $locale + * @param string|Zend_Config|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); } @@ -97,6 +116,10 @@ class Zend_Validate_Float extends Zend_Validate_Abstract return false; } + if (is_float($value)) { + return true; + } + $this->_setValue($value); if ($this->_locale === null) { $locale = localeconv(); diff --git a/libs/Zend/Validate/GreaterThan.php b/libs/Zend/Validate/GreaterThan.php index 3c7b7931c9..53c71ccbc2 100644 --- a/libs/Zend/Validate/GreaterThan.php +++ b/libs/Zend/Validate/GreaterThan.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,22 +14,20 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: GreaterThan.php 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: GreaterThan.php 20358 2010-01-17 19:03:49Z 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) + * @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_GreaterThan extends Zend_Validate_Abstract @@ -42,7 +39,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%'", ); /** @@ -62,11 +59,24 @@ class Zend_Validate_GreaterThan extends Zend_Validate_Abstract /** * Sets validator options * - * @param mixed $min + * @param mixed|Zend_Config $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 85d3e3a7a2..ced156dfe3 100644 --- a/libs/Zend/Validate/Hex.php +++ b/libs/Zend/Validate/Hex.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,22 +14,20 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Hex.php 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: Hex.php 20358 2010-01-17 19:03:49Z 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) + * @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_Hex extends Zend_Validate_Abstract @@ -45,7 +42,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 dd254d5596..04f656dab8 100644 --- a/libs/Zend/Validate/Hostname.php +++ b/libs/Zend/Validate/Hostname.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Hostname.php 17141 2009-07-26 12:49:17Z thomas $ + * @version $Id: Hostname.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -41,7 +41,7 @@ require_once 'Zend/Validate/Ip.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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,27 +101,6 @@ 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 @@ -320,6 +299,13 @@ 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 * @@ -330,16 +316,77 @@ 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($allow = self::ALLOW_DNS, $validateIdn = true, $validateTld = true, Zend_Validate_Ip $ipValidator = null) + public function __construct($options = array()) { - // Set allow options - $this->setAllow($allow); + 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 validation options - $this->_validateIdn = $validateIdn; - $this->_validateTld = $validateTld; + 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']); + } - $this->setIpValidator($ipValidator); + return $this; + } + + /** + * Returns the set ip validator + * + * @return Zend_Validate_Ip + */ + public function getIpValidator() + { + return $this->_options['ip']; } /** @@ -351,7 +398,9 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract if ($ipValidator === null) { $ipValidator = new Zend_Validate_Ip(); } - $this->_ipValidator = $ipValidator; + + $this->_options['ip'] = $ipValidator; + return $this; } /** @@ -361,7 +410,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract */ public function getAllow() { - return $this->_allow; + return $this->_options['allow']; } /** @@ -372,11 +421,21 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract */ public function setAllow($allow) { - $this->_allow = $allow; + $this->_options['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 @@ -385,7 +444,18 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract */ public function setValidateIdn ($allowed) { - $this->_validateIdn = (bool) $allowed; + $this->_options['idn'] = (bool) $allowed; + return $this; + } + + /** + * Returns the set tld option + * + * @return boolean + */ + public function getValidateTld() + { + return $this->_options['tld']; } /** @@ -397,7 +467,8 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract */ public function setValidateTld ($allowed) { - $this->_validateTld = (bool) $allowed; + $this->_options['tld'] = (bool) $allowed; + return $this; } /** @@ -417,11 +488,10 @@ 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->_ipValidator->setTranslator($this->getTranslator())->isValid($value)) { - if (!($this->_allow & self::ALLOW_IP)) { + $this->_options['ip']->setTranslator($this->getTranslator())->isValid($value)) { + if (!($this->_options['allow'] & self::ALLOW_IP)) { $this->_error(self::IP_ADDRESS_NOT_ALLOWED); return false; } else { @@ -452,7 +522,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract // Match TLD against known list $this->_tld = strtolower($matches[1]); - if ($this->_validateTld) { + if ($this->_options['tld']) { if (!in_array($this->_tld, $this->_validTlds)) { $this->_error(self::UNKNOWN_TLD); $status = false; @@ -466,7 +536,7 @@ 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->_validateIdn && isset($this->_validIdns[strtoupper($this->_tld)])) { + if ($this->_options['idn'] && isset($this->_validIdns[strtoupper($this->_tld)])) { if (is_string($this->_validIdns[strtoupper($this->_tld)])) { $regexChars += include($this->_validIdns[strtoupper($this->_tld)]); } else { @@ -475,9 +545,8 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract } // Check each hostname part - $valid = true; + $check = 0; foreach ($domainParts as $domainPart) { - // Decode Punycode domainnames to IDN if (strpos($domainPart, 'xn--') === 0) { $domainPart = $this->decodePunycode(substr($domainPart, 4)); @@ -490,20 +559,16 @@ 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 - $check = false; + $checked = false; foreach($regexChars as $regexKey => $regexChar) { $status = @preg_match($regexChar, $domainPart); - 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) { + if ($status > 0) { $length = 63; if (array_key_exists(strtoupper($this->_tld), $this->_idnLength) && (array_key_exists($regexKey, $this->_idnLength[strtoupper($this->_tld)]))) { @@ -513,23 +578,22 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract if (iconv_strlen($domainPart, 'UTF-8') > $length) { $this->_error(self::INVALID_HOSTNAME); } else { - $check = true; - break 2; + $checked = true; + break; } } } - if (!$check) { - $valid = false; + if ($checked) { + ++$check; } } - // If all labels didn't match, the hostname is invalid - if (!$valid) { + // If one of the labels doesn't match, the hostname is invalid + if ($check !== count($domainParts)) { $this->_error(self::INVALID_HOSTNAME_SCHEMA); $status = false; } - } else { // Hostname not long enough $this->_error(self::UNDECIPHERABLE_TLD); @@ -540,28 +604,20 @@ 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->_allow & self::ALLOW_DNS)) { + if ($status && ($this->_options['allow'] & self::ALLOW_DNS)) { return true; } - } else { + } else if ($this->_options['allow'] & self::ALLOW_DNS) { $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->_allow & self::ALLOW_LOCAL; + $allowLocal = $this->_options['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 f2e3e7a009..38762217d8 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-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Biz.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Biz.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 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 1bcd91eb95..feee54ade2 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-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Cn.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Cn.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 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 19290b300f..413971fec5 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-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Com.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Com.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 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 0888472e61..02f278e2bd 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-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Jp.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Jp.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 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 071651fd96..e230b3f08e 100644 --- a/libs/Zend/Validate/Iban.php +++ b/libs/Zend/Validate/Iban.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Iban.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Iban.php 20532 2010-01-22 20:18:23Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Iban extends Zend_Validate_Abstract @@ -44,9 +44,9 @@ class Zend_Validate_Iban extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOTSUPPORTED => "'%value%' does not have IBAN", - self::FALSEFORMAT => "'%value%' has a false format", - self::CHECKFAILED => "'%value%' has failed the IBAN check" + self::NOTSUPPORTED => "Unknown country within the IBAN '%value%'", + self::FALSEFORMAT => "'%value%' has a false IBAN format", + self::CHECKFAILED => "'%value%' has failed the IBAN check", ); /** @@ -106,11 +106,30 @@ class Zend_Validate_Iban extends Zend_Validate_Abstract /** * Sets validator options * - * @param string|Zend_Locale $locale OPTIONAL + * @param string|Zend_Config|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 (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); } diff --git a/libs/Zend/Validate/Identical.php b/libs/Zend/Validate/Identical.php index d1a046ea9f..3886f3975f 100644 --- a/libs/Zend/Validate/Identical.php +++ b/libs/Zend/Validate/Identical.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Identical.php 17684 2009-08-20 09:20:36Z yoshida@zend.co.jp $ + * @version $Id: Identical.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @see Zend_Validate_Abstract */ @@ -25,7 +25,7 @@ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Identical extends Zend_Validate_Abstract @@ -68,6 +68,14 @@ 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) && (count($token) == 1) && array_key_exists('token', $token)) { + $token = $token['token']; + } + if (null !== $token) { $this->setToken($token); } diff --git a/libs/Zend/Validate/InArray.php b/libs/Zend/Validate/InArray.php index 56940eb1aa..1d8196025d 100644 --- a/libs/Zend/Validate/InArray.php +++ b/libs/Zend/Validate/InArray.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,34 +14,31 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: InArray.php 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: InArray.php 20358 2010-01-17 19:03:49Z 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) + * @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_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", ); /** @@ -57,19 +53,54 @@ class Zend_Validate_InArray extends Zend_Validate_Abstract * * @var boolean */ - protected $_strict; + protected $_strict = false; + + /** + * Whether a recursive search should be done + * + * @var boolean + */ + protected $_recursive = false; /** * Sets validator options * - * @param array $haystack - * @param boolean $strict + * @param array|Zend_Config $haystack * @return void */ - public function __construct(array $haystack, $strict = false) + public function __construct($options) { - $this->setHaystack($haystack) - ->setStrict($strict); + 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']); + } } /** @@ -112,7 +143,29 @@ class Zend_Validate_InArray extends Zend_Validate_Abstract */ public function setStrict($strict) { - $this->_strict = $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; return $this; } @@ -128,11 +181,24 @@ class Zend_Validate_InArray extends Zend_Validate_Abstract public function isValid($value) { $this->_setValue($value); - if (!in_array($value, $this->_haystack, $this->_strict)) { - $this->_error(self::NOT_IN_ARRAY); - return false; + 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; + } } - return true; - } + $this->_error(self::NOT_IN_ARRAY); + return false; + } } diff --git a/libs/Zend/Validate/Int.php b/libs/Zend/Validate/Int.php index 1e34ee3427..4c14f25e47 100644 --- a/libs/Zend/Validate/Int.php +++ b/libs/Zend/Validate/Int.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Int.php 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: Int.php 20532 2010-01-22 20:18:23Z thomas $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Locale/Format.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 a string or a integer", - self::NOT_INT => "'%value%' does not appear to be an integer" + self::INVALID => "Invalid type given, value should be string or integer", + self::NOT_INT => "'%value%' does not appear to be an integer", ); protected $_locale; @@ -53,10 +53,29 @@ class Zend_Validate_Int extends Zend_Validate_Abstract /** * Constructor for the integer validator * - * @param string|Zend_Locale $locale + * @param string|Zend_Config|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); } @@ -97,6 +116,10 @@ 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(); @@ -110,8 +133,7 @@ class Zend_Validate_Int extends Zend_Validate_Abstract } else { try { - if (!Zend_Locale_Format::isInteger($value, array('locale' => 'en')) && - !Zend_Locale_Format::isInteger($value, array('locale' => $this->_locale))) { + if (!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 842a57a8d1..9dfca94219 100644 --- a/libs/Zend/Validate/Interface.php +++ b/libs/Zend/Validate/Interface.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,16 +14,15 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Interface.php 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: Interface.php 20358 2010-01-17 19:03:49Z thomas $ */ - /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Interface @@ -53,19 +51,4 @@ 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 a89bb36fe7..7892b8a62c 100644 --- a/libs/Zend/Validate/Ip.php +++ b/libs/Zend/Validate/Ip.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Ip.php 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: Ip.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -27,7 +27,7 @@ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Ip extends Zend_Validate_Abstract @@ -40,10 +40,78 @@ 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 @@ -59,18 +127,65 @@ 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; + } - 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 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)))) { return false; } + + $value = substr($value, 0, $lastcolon) . ':0:0'; } - return true; - } + 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; + } } diff --git a/libs/Zend/Validate/Isbn.php b/libs/Zend/Validate/Isbn.php new file mode 100644 index 0000000000..0d392ffbb4 --- /dev/null +++ b/libs/Zend/Validate/Isbn.php @@ -0,0 +1,273 @@ +<?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 20358 2010-01-17 19:03:49Z 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'; + + /** + * Validation failure message template definitions. + * + * @var array + */ + protected $_messageTemplates = array( + self::INVALID => "'%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 contains a valid ISBN. + * + * @param string $value + * @return boolean + */ + public function isValid($value) + { + // save value + $value = (string) $value; + $this->_setValue($value); + + switch ($this->_detectFormat()) { + case self::ISBN10: + // sum + $isbn10 = preg_replace('/[^0-9X]/', '', $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 = preg_replace('/[^0-9]/', '', $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::INVALID); + return false; + } + + // validate + if (substr($this->_value, -1) != $checksum) { + $this->_error(self::INVALID); + 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 5d4e155559..e730603f05 100644 --- a/libs/Zend/Validate/LessThan.php +++ b/libs/Zend/Validate/LessThan.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,27 +14,24 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: LessThan.php 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: LessThan.php 20182 2010-01-10 21:12:01Z 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) + * @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_LessThan extends Zend_Validate_Abstract { - const NOT_LESS = 'notLessThan'; /** @@ -62,11 +58,24 @@ class Zend_Validate_LessThan extends Zend_Validate_Abstract /** * Sets validator options * - * @param mixed $max + * @param mixed|Zend_Config $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 304cf4fe70..40eeb993e1 100644 --- a/libs/Zend/Validate/NotEmpty.php +++ b/libs/Zend/Validate/NotEmpty.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: NotEmpty.php 18186 2009-09-17 18:57:00Z matthew $ + * @version $Id: NotEmpty.php 20193 2010-01-11 10:40:43Z thomas $ */ /** @@ -27,14 +27,38 @@ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 */ @@ -44,6 +68,80 @@ 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. @@ -59,21 +157,81 @@ class Zend_Validate_NotEmpty extends Zend_Validate_Abstract return false; } + $type = $this->getType(); $this->_setValue($value); - 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; + + // 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; + } } return true; } - } diff --git a/libs/Zend/Validate/PostCode.php b/libs/Zend/Validate/PostCode.php new file mode 100644 index 0000000000..5892009ab5 --- /dev/null +++ b/libs/Zend/Validate/PostCode.php @@ -0,0 +1,209 @@ +<?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 20532 2010-01-22 20:18:23Z 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, value should be string or integer", + self::NO_MATCH => "'%value%' does not appear to be an 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("Format has to be a not empty string"); + } + } + + /** + * 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 from 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 format from 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("Format has to be a not empty string"); + } + + 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) + { + 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 e4707f5f60..db0f376553 100644 --- a/libs/Zend/Validate/Regex.php +++ b/libs/Zend/Validate/Regex.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,22 +14,20 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Regex.php 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: Regex.php 20358 2010-01-17 19:03:49Z 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) + * @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_Regex extends Zend_Validate_Abstract @@ -43,7 +40,7 @@ class Zend_Validate_Regex extends Zend_Validate_Abstract */ 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::NOT_MATCH => "'%value%' does not match against pattern '%pattern%'", ); /** @@ -63,11 +60,24 @@ class Zend_Validate_Regex extends Zend_Validate_Abstract /** * Sets validator options * - * @param string $pattern + * @param string|Zend_Config $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); } diff --git a/libs/Zend/Validate/Sitemap/Changefreq.php b/libs/Zend/Validate/Sitemap/Changefreq.php index 9ff2715d20..6e4cd61d76 100644 --- a/libs/Zend/Validate/Sitemap/Changefreq.php +++ b/libs/Zend/Validate/Sitemap/Changefreq.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Changefreq.php 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: Changefreq.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -33,7 +33,7 @@ require_once 'Zend/Validate/Abstract.php'; * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Sitemap_Changefreq extends Zend_Validate_Abstract @@ -50,7 +50,7 @@ class Zend_Validate_Sitemap_Changefreq extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_VALID => "'%value%' is not a valid sitemap changefreq", + self::NOT_VALID => "'%value%' is no valid sitemap changefreq", ); /** diff --git a/libs/Zend/Validate/Sitemap/Lastmod.php b/libs/Zend/Validate/Sitemap/Lastmod.php index 4f01d1a781..c738a5570f 100644 --- a/libs/Zend/Validate/Sitemap/Lastmod.php +++ b/libs/Zend/Validate/Sitemap/Lastmod.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Lastmod.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Lastmod.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -33,7 +33,7 @@ require_once 'Zend/Validate/Abstract.php'; * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Sitemap_Lastmod extends Zend_Validate_Abstract @@ -42,7 +42,7 @@ 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]){2}(\\+|-)([0-1][0-9]|2[0-3]):[0-5][0-9])?$/m'; + 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])?$/'; /** * Validation key for not valid @@ -56,7 +56,7 @@ class Zend_Validate_Sitemap_Lastmod extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_VALID => "'%value%' is not a valid sitemap lastmod", + self::NOT_VALID => "'%value%' is no valid sitemap lastmod", ); /** @@ -77,5 +77,4 @@ class Zend_Validate_Sitemap_Lastmod extends Zend_Validate_Abstract 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 92d5272030..0ea313f3ba 100644 --- a/libs/Zend/Validate/Sitemap/Loc.php +++ b/libs/Zend/Validate/Sitemap/Loc.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Loc.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Loc.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -38,7 +38,7 @@ require_once 'Zend/Uri.php'; * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Sitemap_Loc extends Zend_Validate_Abstract @@ -55,7 +55,7 @@ class Zend_Validate_Sitemap_Loc extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_VALID => "'%value%' is not a valid sitemap location", + self::NOT_VALID => "'%value%' is no valid sitemap location", ); /** diff --git a/libs/Zend/Validate/Sitemap/Priority.php b/libs/Zend/Validate/Sitemap/Priority.php index 3568a9fc0f..a045daf061 100644 --- a/libs/Zend/Validate/Sitemap/Priority.php +++ b/libs/Zend/Validate/Sitemap/Priority.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Priority.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Priority.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -33,7 +33,7 @@ require_once 'Zend/Validate/Abstract.php'; * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Sitemap_Priority extends Zend_Validate_Abstract @@ -50,7 +50,7 @@ class Zend_Validate_Sitemap_Priority extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_VALID => "'%value%' is not a valid sitemap priority", + self::NOT_VALID => "'%value%' is no valid sitemap priority", ); /** diff --git a/libs/Zend/Validate/StringLength.php b/libs/Zend/Validate/StringLength.php index 7ec9125f92..c9c5b80ff3 100644 --- a/libs/Zend/Validate/StringLength.php +++ b/libs/Zend/Validate/StringLength.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: StringLength.php 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: StringLength.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -27,7 +27,7 @@ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_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 greater than %max% characters long" + self::TOO_LONG => "'%value%' is more than %max% characters long", ); /** @@ -79,15 +79,39 @@ class Zend_Validate_StringLength extends Zend_Validate_Abstract /** * Sets validator options * - * @param integer $min - * @param integer $max + * @param integer|array|Zend_Config $options * @return void */ - public function __construct($min = 0, $max = null, $encoding = null) + public function __construct($options = array()) { - $this->setMin($min); - $this->setMax($max); - $this->setEncoding($encoding); + 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']); + } } /** |