Index: Int.php =================================================================== --- Int.php (revision 9271) +++ Int.php (working copy) @@ -37,15 +37,37 @@ { const NOT_INT = 'notInt'; + const NOT_BIG_INT = 'notBigInt'; /** * @var array */ protected $_messageTemplates = array( - self::NOT_INT => "'%value%' does not appear to be an integer" + self::NOT_INT => "'%value%' does not appear to be an integer", + self::NOT_BIG_INT => "'%value%' is outside the range of PHP integers on this system and does not appear to be an integer" ); /** + * Should validation fail if the integer exceeds PHP boundaries + * + * @var boolean + */ + protected $_failOnPhpIntegerBoundary = true; + + /** + * Set wether or not the validation should fail if the integer exceeds + * PHP boundaries. See the PHP_INT_MAX constant. + * + * @param boolean $fail + * @return Zend_Validate_Int + */ + public function setFailOnPhpIntegerBoundary($fail = true) + { + $this->_failOnPhpIntegerBoundary = (bool) $fail; + return $this; + } + + /** * Defined by Zend_Validate_Interface * * Returns true if and only if $value is a valid integer @@ -64,12 +86,19 @@ $valueFiltered = str_replace($locale['decimal_point'], '.', $valueString); $valueFiltered = str_replace($locale['thousands_sep'], '', $valueFiltered); - if (strval(intval($valueFiltered)) != $valueFiltered) { - $this->_error(); + // check if values exceed integer boundaries + if ((float) $valueString > PHP_INT_MAX and !$this->_failOnPhpIntegerBoundary) { + require_once 'Zend/Locale/Format.php'; + $localeNumber = Zend_Locale_Format::toInteger($value, array('locale' => 'en_US')); + if (!Zend_Locale_Format::isInteger($localeNumber, array('locale' => 'en_US'))) { + $this->_error(self::NOT_BIG_INT); + return false; + } + } else if (strval(intval($valueFiltered)) != $valueFiltered) { + $this->_error(self::NOT_INT); return false; } return true; } - }