diff options
Diffstat (limited to 'libs/Zend/Validate/Int.php')
-rw-r--r-- | libs/Zend/Validate/Int.php | 38 |
1 files changed, 30 insertions, 8 deletions
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; } |