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: Date.php 13371 2008-12-19 11:41:09Z thomas $
* @version $Id: Date.php 17696 2009-08-20 20:12:33Z thomas $
*/
/**
@ -27,24 +27,14 @@ 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_Date extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value does not follow the YYYY-MM-DD format
*/
const NOT_YYYY_MM_DD = 'dateNotYYYY-MM-DD';
/**
* Validation failure message key for when the value does not appear to be a valid date
*/
const INVALID = 'dateInvalid';
/**
* Validation failure message key for when the value does not fit the given dateformat or locale
*/
const NOT_YYYY_MM_DD = 'dateNotYYYY-MM-DD';
const INVALID_DATE = 'dateInvalidDate';
const FALSEFORMAT = 'dateFalseFormat';
/**
@ -53,8 +43,9 @@ class Zend_Validate_Date extends Zend_Validate_Abstract
* @var array
*/
protected $_messageTemplates = array(
self::INVALID => "Invalid type given, value should be string, integer, array or Zend_Date",
self::NOT_YYYY_MM_DD => "'%value%' is not of the format YYYY-MM-DD",
self::INVALID => "'%value%' does not appear to be a valid date",
self::INVALID_DATE => "'%value%' does not appear to be a valid date",
self::FALSEFORMAT => "'%value%' does not fit given date format"
);
@ -82,6 +73,13 @@ class Zend_Validate_Date extends Zend_Validate_Abstract
public function __construct($format = null, $locale = null)
{
$this->setFormat($format);
if ($locale === null) {
require_once 'Zend/Registry.php';
if (Zend_Registry::isRegistered('Zend_Locale')) {
$locale = Zend_Registry::get('Zend_Locale');
}
}
if ($locale !== null) {
$this->setLocale($locale);
}
@ -139,35 +137,40 @@ class Zend_Validate_Date extends Zend_Validate_Abstract
* If optional $format or $locale is set the date format is checked
* according to Zend_Date, see Zend_Date::isDate()
*
* @param string $value
* @param string|array|Zend_Date $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
if (!is_string($value) && !is_int($value) && !is_float($value) &&
!is_array($value) && !($value instanceof Zend_Date)) {
$this->_error(self::INVALID);
return false;
}
$this->_setValue($valueString);
$this->_setValue($value);
if (($this->_format !== null) or ($this->_locale !== null)) {
if (($this->_format !== null) || ($this->_locale !== null) || is_array($value) ||
$value instanceof Zend_Date) {
require_once 'Zend/Date.php';
if (!Zend_Date::isDate($value, $this->_format, $this->_locale)) {
if ($this->_checkFormat($value) === false) {
$this->_error(self::FALSEFORMAT);
} else {
$this->_error(self::INVALID);
$this->_error(self::INVALID_DATE);
}
return false;
}
} else {
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $valueString)) {
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) {
$this->_error(self::NOT_YYYY_MM_DD);
return false;
}
list($year, $month, $day) = sscanf($valueString, '%d-%d-%d');
list($year, $month, $day) = sscanf($value, '%d-%d-%d');
if (!checkdate($month, $day, $year)) {
$this->_error(self::INVALID);
$this->_error(self::INVALID_DATE);
return false;
}
}