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