import v1.1.0_RC2 | 2009-09-20

This commit is contained in:
2019-07-17 22:19:00 +02:00
parent 3b7ba80568
commit 38c146901c
2504 changed files with 101817 additions and 62316 deletions

View File

@ -14,9 +14,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: Int.php 13375 2008-12-19 14:16:40Z thomas $
* @version $Id: Int.php 17470 2009-08-08 22:27:09Z thomas $
*/
/**
@ -32,17 +32,19 @@ require_once 'Zend/Locale/Format.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_Int extends Zend_Validate_Abstract
{
const INVALID = 'intInvalid';
const NOT_INT = 'notInt';
/**
* @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"
);
@ -55,7 +57,9 @@ class Zend_Validate_Int extends Zend_Validate_Abstract
*/
public function __construct($locale = null)
{
$this->setLocale($locale);
if ($locale !== null) {
$this->setLocale($locale);
}
}
/**
@ -83,26 +87,38 @@ class Zend_Validate_Int extends Zend_Validate_Abstract
*
* Returns true if and only if $value is a valid integer
*
* @param string $value
* @param string|integer $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if (is_bool($value)) {
$this->_error();
if (!is_string($value) && !is_int($value) && !is_float($value)) {
$this->_error(self::INVALID);
return false;
}
try {
if (!Zend_Locale_Format::isInteger($value, array('locale' => $this->_locale))) {
$this->_error();
$this->_setValue($value);
if ($this->_locale === null) {
$locale = localeconv();
$valueFiltered = str_replace($locale['decimal_point'], '.', $value);
$valueFiltered = str_replace($locale['thousands_sep'], '', $valueFiltered);
if (strval(intval($valueFiltered)) != $valueFiltered) {
$this->_error(self::NOT_INT);
return false;
}
} else {
try {
if (!Zend_Locale_Format::isInteger($value, array('locale' => 'en')) &&
!Zend_Locale_Format::isInteger($value, array('locale' => $this->_locale))) {
$this->_error(self::NOT_INT);
return false;
}
} catch (Zend_Locale_Exception $e) {
$this->_error(self::NOT_INT);
return false;
}
} catch (Zend_Locale_Exception $e) {
$this->_error();
return false;
}
return true;