Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Zend_Validate_Date Class Reference
Inheritance diagram for Zend_Validate_Date:
Zend_Validate_Abstract Zend_Validate_Interface

Public Member Functions

 __construct ($options=array())
 
 getLocale ()
 
 setLocale ($locale=null)
 
 getFormat ()
 
 setFormat ($format=null)
 
 isValid ($value)
 
- Public Member Functions inherited from Zend_Validate_Abstract
 getMessages ()
 
 getMessageVariables ()
 
 getMessageTemplates ()
 
 setMessage ($messageString, $messageKey=null)
 
 setMessages (array $messages)
 
 __get ($property)
 
 getErrors ()
 
 setObscureValue ($flag)
 
 getObscureValue ()
 
 setTranslator ($translator=null)
 
 getTranslator ()
 
 hasTranslator ()
 
 setDisableTranslator ($flag)
 
 translatorIsDisabled ()
 

Data Fields

const INVALID = 'dateInvalid'
 
const INVALID_DATE = 'dateInvalidDate'
 
const FALSEFORMAT = 'dateFalseFormat'
 

Protected Attributes

 $_messageTemplates
 
 $_messageVariables
 
 $_format
 
 $_locale
 
- Protected Attributes inherited from Zend_Validate_Abstract
 $_value
 
 $_messageVariables = array()
 
 $_messageTemplates = array()
 
 $_messages = array()
 
 $_obscureValue = false
 
 $_errors = array()
 
 $_translator
 
 $_translatorDisabled = false
 

Additional Inherited Members

- Static Public Member Functions inherited from Zend_Validate_Abstract
static setDefaultTranslator ($translator=null)
 
static getDefaultTranslator ()
 
static hasDefaultTranslator ()
 
static getMessageLength ()
 
static setMessageLength ($length=-1)
 
- Protected Member Functions inherited from Zend_Validate_Abstract
 _createMessage ($messageKey, $value)
 
 _implodeRecursive (array $pieces)
 
 _error ($messageKey, $value=null)
 
 _setValue ($value)
 
- Static Protected Attributes inherited from Zend_Validate_Abstract
static $_defaultTranslator
 
static $_messageLength = -1
 

Detailed Description

Definition at line 33 of file Date.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = array())

Sets validator options

Parameters
string | array | Zend_Config$optionsOPTIONAL

Definition at line 76 of file Date.php.

77  {
78  if ($options instanceof Zend_Config) {
79  $options = $options->toArray();
80  } else if (!is_array($options)) {
81  $options = func_get_args();
82  $temp['format'] = array_shift($options);
83  if (!empty($options)) {
84  $temp['locale'] = array_shift($options);
85  }
86 
87  $options = $temp;
88  }
89 
90  if (array_key_exists('format', $options)) {
91  $this->setFormat($options['format']);
92  }
93 
94  if (!array_key_exists('locale', $options)) {
95  #require_once 'Zend/Registry.php';
96  if (Zend_Registry::isRegistered('Zend_Locale')) {
97  $options['locale'] = Zend_Registry::get('Zend_Locale');
98  }
99  }
100 
101  if (array_key_exists('locale', $options)) {
102  $this->setLocale($options['locale']);
103  }
104  }
setFormat($format=null)
Definition: Date.php:145
static isRegistered($index)
Definition: Registry.php:178
setLocale($locale=null)
Definition: Date.php:122
static get($index)
Definition: Registry.php:141

Member Function Documentation

◆ getFormat()

getFormat ( )

Returns the locale option

Returns
string|null

Definition at line 134 of file Date.php.

135  {
136  return $this->_format;
137  }

◆ getLocale()

getLocale ( )

Returns the locale option

Returns
string|Zend_Locale|null

Definition at line 111 of file Date.php.

112  {
113  return $this->_locale;
114  }

◆ isValid()

isValid (   $value)

Defined by Zend_Validate_Interface

Returns true if $value is a valid date of the format YYYY-MM-DD If optional $format or $locale is set the date format is checked according to Zend_Date, see Zend_Date::isDate()

Parameters
string | array | Zend_Date$value
Returns
boolean

Implements Zend_Validate_Interface.

Definition at line 161 of file Date.php.

162  {
163  if (!is_string($value) && !is_int($value) && !is_float($value) &&
164  !is_array($value) && !($value instanceof Zend_Date)) {
165  $this->_error(self::INVALID);
166  return false;
167  }
168 
169  $this->_setValue($value);
170 
171  if (($this->_format !== null) || ($this->_locale !== null) || is_array($value) ||
172  $value instanceof Zend_Date) {
173  #require_once 'Zend/Date.php';
174  if (!Zend_Date::isDate($value, $this->_format, $this->_locale)) {
175  if ($this->_checkFormat($value) === false) {
176  $this->_error(self::FALSEFORMAT);
177  } else {
178  $this->_error(self::INVALID_DATE);
179  }
180  return false;
181  }
182  } else {
183  if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) {
184  $this->_format = 'yyyy-MM-dd';
185  $this->_error(self::FALSEFORMAT);
186  $this->_format = null;
187  return false;
188  }
189 
190  list($year, $month, $day) = sscanf($value, '%d-%d-%d');
191 
192  if (!checkdate($month, $day, $year)) {
193  $this->_error(self::INVALID_DATE);
194  return false;
195  }
196  }
197 
198  return true;
199  }
_error($messageKey, $value=null)
Definition: Abstract.php:284
$value
Definition: gender.phtml:16

◆ setFormat()

setFormat (   $format = null)

Sets the format option

Parameters
string$format
Returns
Zend_Validate_Date provides a fluent interface

Definition at line 145 of file Date.php.

146  {
147  $this->_format = $format;
148  return $this;
149  }
$format
Definition: list.phtml:12

◆ setLocale()

setLocale (   $locale = null)

Sets the locale option

Parameters
string | Zend_Locale$locale
Returns
Zend_Validate_Date provides a fluent interface

Definition at line 122 of file Date.php.

123  {
124  #require_once 'Zend/Locale.php';
125  $this->_locale = Zend_Locale::findLocale($locale);
126  return $this;
127  }
static findLocale($locale=null)
Definition: Locale.php:1740

Field Documentation

◆ $_format

$_format
protected

Definition at line 62 of file Date.php.

◆ $_locale

$_locale
protected

Definition at line 69 of file Date.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::INVALID => "Invalid type given. String, integer, array or Zend_Date expected",
self::INVALID_DATE => "'%value%' does not appear to be a valid date",
self::FALSEFORMAT => "'%value%' does not fit the date format '%format%'",
)

Definition at line 44 of file Date.php.

◆ $_messageVariables

$_messageVariables
protected
Initial value:
= array(
'format' => '_format'
)

Definition at line 53 of file Date.php.

◆ FALSEFORMAT

const FALSEFORMAT = 'dateFalseFormat'

Definition at line 37 of file Date.php.

◆ INVALID

const INVALID = 'dateInvalid'

Definition at line 35 of file Date.php.

◆ INVALID_DATE

const INVALID_DATE = 'dateInvalidDate'

Definition at line 36 of file Date.php.


The documentation for this class was generated from the following file: