diff options
Diffstat (limited to 'libs/Zend/Validate/Date.php')
-rw-r--r-- | libs/Zend/Validate/Date.php | 63 |
1 files changed, 42 insertions, 21 deletions
diff --git a/libs/Zend/Validate/Date.php b/libs/Zend/Validate/Date.php index 5dbcc6d702..22e49b7aee 100644 --- a/libs/Zend/Validate/Date.php +++ b/libs/Zend/Validate/Date.php @@ -14,27 +14,26 @@ * * @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: Date.php 17696 2009-08-20 20:12:33Z thomas $ + * @version $Id: Date.php 20358 2010-01-17 19:03:49Z thomas $ */ /** * @see Zend_Validate_Abstract */ -require_once 'Zend/Validate/Abstract.php'; +// require_once 'Zend/Validate/Abstract.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_Date extends Zend_Validate_Abstract { const INVALID = 'dateInvalid'; - const NOT_YYYY_MM_DD = 'dateNotYYYY-MM-DD'; - const INVALID_DATE = 'dateInvalidDate'; + const INVALID_DATE = 'dateInvalidDate'; const FALSEFORMAT = 'dateFalseFormat'; /** @@ -44,9 +43,15 @@ class Zend_Validate_Date extends Zend_Validate_Abstract */ 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_DATE => "'%value%' does not appear to be a valid date", - self::FALSEFORMAT => "'%value%' does not fit given date format" + self::FALSEFORMAT => "'%value%' does not fit the date format '%format%'", + ); + + /** + * @var array + */ + protected $_messageVariables = array( + 'format' => '_format' ); /** @@ -66,22 +71,36 @@ class Zend_Validate_Date extends Zend_Validate_Abstract /** * Sets validator options * - * @param string $format OPTIONAL - * @param string|Zend_Locale $locale OPTIONAL + * @param string|Zend_Config $options OPTIONAL * @return void */ - public function __construct($format = null, $locale = null) + public function __construct($options = array()) { - $this->setFormat($format); - if ($locale === null) { - require_once 'Zend/Registry.php'; + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } else if (!is_array($options)) { + $options = func_get_args(); + $temp['format'] = array_shift($options); + if (!empty($options)) { + $temp['locale'] = array_shift($options); + } + + $options = $temp; + } + + if (array_key_exists('format', $options)) { + $this->setFormat($options['format']); + } + + if (!array_key_exists('locale', $options)) { + // require_once 'Zend/Registry.php'; if (Zend_Registry::isRegistered('Zend_Locale')) { - $locale = Zend_Registry::get('Zend_Locale'); + $options['locale'] = Zend_Registry::get('Zend_Locale'); } } - if ($locale !== null) { - $this->setLocale($locale); + if (array_key_exists('locale', $options)) { + $this->setLocale($options['locale']); } } @@ -103,7 +122,7 @@ class Zend_Validate_Date extends Zend_Validate_Abstract */ public function setLocale($locale = null) { - require_once 'Zend/Locale.php'; + // require_once 'Zend/Locale.php'; $this->_locale = Zend_Locale::findLocale($locale); return $this; } @@ -152,7 +171,7 @@ class Zend_Validate_Date extends Zend_Validate_Abstract if (($this->_format !== null) || ($this->_locale !== null) || is_array($value) || $value instanceof Zend_Date) { - require_once 'Zend/Date.php'; + // require_once 'Zend/Date.php'; if (!Zend_Date::isDate($value, $this->_format, $this->_locale)) { if ($this->_checkFormat($value) === false) { $this->_error(self::FALSEFORMAT); @@ -163,7 +182,9 @@ class Zend_Validate_Date extends Zend_Validate_Abstract } } else { if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) { - $this->_error(self::NOT_YYYY_MM_DD); + $this->_format = 'yyyy-MM-dd'; + $this->_error(self::FALSEFORMAT); + $this->_format = null; return false; } @@ -187,7 +208,7 @@ class Zend_Validate_Date extends Zend_Validate_Abstract private function _checkFormat($value) { try { - require_once 'Zend/Locale/Format.php'; + // require_once 'Zend/Locale/Format.php'; $parsed = Zend_Locale_Format::getDate($value, array( 'date_format' => $this->_format, 'format_type' => 'iso', 'fix_date' => false)); |