diff options
author | robocoder <anthon.pang@gmail.com> | 2010-05-07 07:42:19 +0400 |
---|---|---|
committer | robocoder <anthon.pang@gmail.com> | 2010-05-07 07:42:19 +0400 |
commit | 798d243e0b506ac7385f824c966e04720bd50955 (patch) | |
tree | 94101e21bd8d8fdd0f9bde8a09c581c2db4a4834 /libs/Zend/Validate | |
parent | a47fa6fe1afa06fbe4638dacb61e6331108897ea (diff) |
fixes #1330 - ZF 1.10.4 update
git-svn-id: http://dev.piwik.org/svn/trunk@2150 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'libs/Zend/Validate')
-rw-r--r-- | libs/Zend/Validate/Abstract.php | 22 | ||||
-rw-r--r-- | libs/Zend/Validate/Barcode.php | 4 | ||||
-rw-r--r-- | libs/Zend/Validate/File/ExcludeMimeType.php | 4 | ||||
-rw-r--r-- | libs/Zend/Validate/File/MimeType.php | 13 | ||||
-rw-r--r-- | libs/Zend/Validate/Isbn.php | 22 |
5 files changed, 45 insertions, 20 deletions
diff --git a/libs/Zend/Validate/Abstract.php b/libs/Zend/Validate/Abstract.php index 49cd7f10ff..cbecc5eebf 100644 --- a/libs/Zend/Validate/Abstract.php +++ b/libs/Zend/Validate/Abstract.php @@ -16,7 +16,7 @@ * @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: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Abstract.php 21726 2010-03-31 19:57:27Z rob $ */ /** @@ -353,6 +353,16 @@ abstract class Zend_Validate_Abstract implements Zend_Validate_Interface } /** + * Does this validator have its own specific translator? + * + * @return bool + */ + public function hasTranslator() + { + return (bool)$this->_translator; + } + + /** * Set default translation object for all validate objects * * @param Zend_Translate|Zend_Translate_Adapter|null $translator @@ -393,6 +403,16 @@ abstract class Zend_Validate_Abstract implements Zend_Validate_Interface } /** + * Is there a default translation object set? + * + * @return boolean + */ + public static function hasDefaultTranslator() + { + return (bool)self::$_defaultTranslator; + } + + /** * Indicate whether or not translation should be disabled * * @param bool $flag diff --git a/libs/Zend/Validate/Barcode.php b/libs/Zend/Validate/Barcode.php index 40bb9cb623..111010880e 100644 --- a/libs/Zend/Validate/Barcode.php +++ b/libs/Zend/Validate/Barcode.php @@ -16,7 +16,7 @@ * @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: Barcode.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: Barcode.php 21748 2010-04-03 10:29:56Z thomas $ */ /** @@ -189,7 +189,7 @@ class Zend_Validate_Barcode extends Zend_Validate_Abstract return false; } - $this->_value = (string) $value; + $this->_setValue($value); $adapter = $this->getAdapter(); $this->_length = $adapter->getLength(); $result = $adapter->checkLength($value); diff --git a/libs/Zend/Validate/File/ExcludeMimeType.php b/libs/Zend/Validate/File/ExcludeMimeType.php index 0c28aa1d7b..436caa1f02 100644 --- a/libs/Zend/Validate/File/ExcludeMimeType.php +++ b/libs/Zend/Validate/File/ExcludeMimeType.php @@ -16,7 +16,7 @@ * @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: ExcludeMimeType.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: ExcludeMimeType.php 21936 2010-04-18 16:23:34Z thomas $ */ /** @@ -73,7 +73,7 @@ class Zend_Validate_File_ExcludeMimeType extends Zend_Validate_File_MimeType $mime = new finfo($const); } - if ($mime !== false) { + if (!empty($mime)) { $this->_type = $mime->file($value); } unset($mime); diff --git a/libs/Zend/Validate/File/MimeType.php b/libs/Zend/Validate/File/MimeType.php index 26d996411f..a31a7d35a3 100644 --- a/libs/Zend/Validate/File/MimeType.php +++ b/libs/Zend/Validate/File/MimeType.php @@ -16,7 +16,7 @@ * @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: MimeType.php 21472 2010-03-11 22:16:55Z thomas $ + * @version $Id: MimeType.php 21936 2010-04-18 16:23:34Z thomas $ */ /** @@ -197,7 +197,7 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract } else { $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME; $this->_finfo = @finfo_open($const, $file); - if ($this->_finfo === false) { + if (empty($this->_finfo)) { $this->_finfo = null; // require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception('The given magicfile is not accepted by finfo'); @@ -332,19 +332,18 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract $mimefile = $this->getMagicFile(); if (class_exists('finfo', false)) { $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME; - if (!empty($mimefile) && !empty($this->_finfo)) { + if (!empty($mimefile) && empty($this->_finfo)) { $this->_finfo = @finfo_open($const, $mimefile); } - if ($this->_finfo === false) { + if (empty($this->_finfo)) { $this->_finfo = @finfo_open($const); } - if ($this->_finfo !== false) { + $this->_type = null; + if (!empty($this->_finfo)) { $this->_type = finfo_file($this->_finfo, $value); } - - unset($this->_finfo); } if (empty($this->_type) && diff --git a/libs/Zend/Validate/Isbn.php b/libs/Zend/Validate/Isbn.php index bbcd370c87..e977871b20 100644 --- a/libs/Zend/Validate/Isbn.php +++ b/libs/Zend/Validate/Isbn.php @@ -16,7 +16,7 @@ * @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 $ + * @version $Id: Isbn.php 21761 2010-04-04 21:37:18Z thomas $ */ /** @@ -36,6 +36,7 @@ class Zend_Validate_Isbn extends Zend_Validate_Abstract const ISBN10 = '10'; const ISBN13 = '13'; const INVALID = 'isbnInvalid'; + const NO_ISBN = 'isbnNoIsbn'; /** * Validation failure message template definitions. @@ -43,7 +44,8 @@ class Zend_Validate_Isbn extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::INVALID => "'%value%' is no valid ISBN number", + self::INVALID => "Invalid type given, value should be string or integer", + self::NO_ISBN => "'%value%' is no valid ISBN number", ); /** @@ -145,21 +147,25 @@ class Zend_Validate_Isbn extends Zend_Validate_Abstract /** * Defined by Zend_Validate_Interface. * - * Returns true if and only if $value contains a valid ISBN. + * Returns true if and only if $value is a valid ISBN. * * @param string $value * @return boolean */ public function isValid($value) { - // save value + if (!is_string($value) && !is_int($value)) { + $this->_error(self::INVALID); + return false; + } + $value = (string) $value; $this->_setValue($value); switch ($this->_detectFormat()) { case self::ISBN10: // sum - $isbn10 = preg_replace('/[^0-9X]/', '', $value); + $isbn10 = str_replace($this->_separator, '', $value); $sum = 0; for ($i = 0; $i < 9; $i++) { $sum += (10 - $i) * $isbn10{$i}; @@ -176,7 +182,7 @@ class Zend_Validate_Isbn extends Zend_Validate_Abstract case self::ISBN13: // sum - $isbn13 = preg_replace('/[^0-9]/', '', $value); + $isbn13 = str_replace($this->_separator, '', $value); $sum = 0; for ($i = 0; $i < 12; $i++) { if ($i % 2 == 0) { @@ -193,13 +199,13 @@ class Zend_Validate_Isbn extends Zend_Validate_Abstract break; default: - $this->_error(self::INVALID); + $this->_error(self::NO_ISBN); return false; } // validate if (substr($this->_value, -1) != $checksum) { - $this->_error(self::INVALID); + $this->_error(self::NO_ISBN); return false; } return true; |