diff options
author | robocoder <anthon.pang@gmail.com> | 2009-09-07 22:40:52 +0400 |
---|---|---|
committer | robocoder <anthon.pang@gmail.com> | 2009-09-07 22:40:52 +0400 |
commit | ada0ccf4ecfd94428d0b2a74ea85607722989aaa (patch) | |
tree | b205427c2cbb4c03d741b62ed6cd64f763a99bef /libs/Zend/Validate/Barcode | |
parent | 6392a745552a8804197385f6512d707c40c50feb (diff) |
Fixes #497 - update to Zend Framework 1.9.2 (subset); remove svn:keywords to preserve the original $Id; misc changes to handle fetchRow() sometimes returning null (instead of false)
git-svn-id: http://dev.piwik.org/svn/trunk@1454 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'libs/Zend/Validate/Barcode')
-rw-r--r-- | libs/Zend/Validate/Barcode/Ean13.php | 26 | ||||
-rw-r--r-- | libs/Zend/Validate/Barcode/UpcA.php | 19 |
2 files changed, 29 insertions, 16 deletions
diff --git a/libs/Zend/Validate/Barcode/Ean13.php b/libs/Zend/Validate/Barcode/Ean13.php index 7be797df86..068809248c 100644 --- a/libs/Zend/Validate/Barcode/Ean13.php +++ b/libs/Zend/Validate/Barcode/Ean13.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 8210 2008-02-20 14:09:05Z andries $ + * @version $Id: Ean13.php 16223 2009-06-21 20:04:53Z thomas $ */ @@ -30,7 +30,7 @@ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_Barcode_Ean13 extends Zend_Validate_Abstract @@ -48,6 +48,12 @@ class Zend_Validate_Barcode_Ean13 extends Zend_Validate_Abstract const INVALID_LENGTH = 'invalidLength'; /** + * Validation failure message key for when the value + * does not only contain numeric characters + */ + const NOT_NUMERIC = 'ean13NotNumeric'; + + /** * Validation failure message template definitions * * @var array @@ -55,6 +61,7 @@ class Zend_Validate_Barcode_Ean13 extends Zend_Validate_Abstract 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", ); /** @@ -67,15 +74,18 @@ class Zend_Validate_Barcode_Ean13 extends Zend_Validate_Abstract */ public function isValid($value) { - $valueString = (string) $value; - $this->_setValue($valueString); + if (!is_string($value) || !ctype_digit($value)) { + $this->_error(self::NOT_NUMERIC); + return false; + } - if (strlen($valueString) !== 13) { + $this->_setValue($value); + if (strlen($value) !== 13) { $this->_error(self::INVALID_LENGTH); return false; } - $barcode = strrev(substr($valueString, 0, -1)); + $barcode = strrev(substr($value, 0, -1)); $oddSum = 0; $evenSum = 0; @@ -90,7 +100,7 @@ class Zend_Validate_Barcode_Ean13 extends Zend_Validate_Abstract $calculation = ($oddSum + $evenSum) % 10; $checksum = ($calculation === 0) ? 0 : 10 - $calculation; - if ($valueString[12] != $checksum) { + if ($value[12] != $checksum) { $this->_error(self::INVALID); return false; } diff --git a/libs/Zend/Validate/Barcode/UpcA.php b/libs/Zend/Validate/Barcode/UpcA.php index c584e818da..cf33f31fab 100644 --- a/libs/Zend/Validate/Barcode/UpcA.php +++ b/libs/Zend/Validate/Barcode/UpcA.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: UpcA.php 8210 2008-02-20 14:09:05Z andries $ + * @version $Id: UpcA.php 16223 2009-06-21 20:04:53Z thomas $ */ @@ -30,7 +30,7 @@ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Validate_Barcode_UpcA extends Zend_Validate_Abstract @@ -67,15 +67,18 @@ class Zend_Validate_Barcode_UpcA extends Zend_Validate_Abstract */ public function isValid($value) { - $valueString = (string) $value; - $this->_setValue($valueString); + if (!is_string($value)) { + $this->_error(self::INVALID); + return false; + } - if (strlen($valueString) !== 12) { + $this->_setValue($value); + if (strlen($value) !== 12) { $this->_error(self::INVALID_LENGTH); return false; } - $barcode = substr($valueString, 0, -1); + $barcode = substr($value, 0, -1); $oddSum = 0; $evenSum = 0; @@ -90,7 +93,7 @@ class Zend_Validate_Barcode_UpcA extends Zend_Validate_Abstract $calculation = ($oddSum + $evenSum) % 10; $checksum = ($calculation === 0) ? 0 : 10 - $calculation; - if ($valueString[11] != $checksum) { + if ($value[11] != $checksum) { $this->_error(self::INVALID); return false; } |