Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes
Zend_Validate Class Reference
Inheritance diagram for Zend_Validate:
Zend_Validate_Interface ExistingValidate

Public Member Functions

 addValidator (Zend_Validate_Interface $validator, $breakChainOnFailure=false)
 
 isValid ($value)
 
 getMessages ()
 
 getErrors ()
 

Static Public Member Functions

static getDefaultNamespaces ()
 
static setDefaultNamespaces ($namespace)
 
static addDefaultNamespaces ($namespace)
 
static hasDefaultNamespaces ()
 
static is ($value, $classBaseName, array $args=array(), $namespaces=array())
 
static getMessageLength ()
 
static setMessageLength ($length=-1)
 
static getDefaultTranslator ($translator=null)
 
static setDefaultTranslator ($translator=null)
 

Protected Attributes

 $_validators = array()
 
 $_messages = array()
 
 $_errors = array()
 

Static Protected Attributes

static $_defaultNamespaces = array()
 

Detailed Description

Definition at line 33 of file Validate.php.

Member Function Documentation

◆ addDefaultNamespaces()

static addDefaultNamespaces (   $namespace)
static

Adds a new default namespace

Parameters
array | string$namespace
Returns
null

Definition at line 168 of file Validate.php.

169  {
170  if (!is_array($namespace)) {
171  $namespace = array((string) $namespace);
172  }
173 
174  self::$_defaultNamespaces = array_unique(array_merge(self::$_defaultNamespaces, $namespace));
175  }

◆ addValidator()

addValidator ( Zend_Validate_Interface  $validator,
  $breakChainOnFailure = false 
)

Adds a validator to the end of the chain

If $breakChainOnFailure is true, then if the validator fails, the next validator in the chain, if one exists, will not be executed.

Parameters
Zend_Validate_Interface$validator
boolean$breakChainOnFailure
Returns
Zend_Validate Provides a fluent interface

Definition at line 74 of file Validate.php.

75  {
76  $this->_validators[] = array(
77  'instance' => $validator,
78  'breakChainOnFailure' => (boolean) $breakChainOnFailure
79  );
80  return $this;
81  }

◆ getDefaultNamespaces()

static getDefaultNamespaces ( )
static

Returns the set default namespaces

Returns
array

Definition at line 142 of file Validate.php.

143  {
145  }
static $_defaultNamespaces
Definition: Validate.php:54

◆ getDefaultTranslator()

static getDefaultTranslator (   $translator = null)
static

Returns the default translation object

Returns
Zend_Translate_Adapter|null

Definition at line 274 of file Validate.php.

275  {
276  #require_once 'Zend/Validate/Abstract.php';
278  }
static getDefaultTranslator()
Definition: Abstract.php:415

◆ getErrors()

getErrors ( )

Defined by Zend_Validate_Interface

Returns array of validation failure message codes

Returns
array
Deprecated:
Since 1.5.0

Definition at line 132 of file Validate.php.

133  {
134  return $this->_errors;
135  }

◆ getMessageLength()

static getMessageLength ( )
static

Returns the maximum allowed message length

Returns
integer

Definition at line 252 of file Validate.php.

253  {
254  #require_once 'Zend/Validate/Abstract.php';
256  }
static getMessageLength()
Definition: Abstract.php:469

◆ getMessages()

getMessages ( )

Defined by Zend_Validate_Interface

Returns array of validation failure messages

Returns
array

Implements Zend_Validate_Interface.

Definition at line 119 of file Validate.php.

120  {
121  return $this->_messages;
122  }

◆ hasDefaultNamespaces()

static hasDefaultNamespaces ( )
static

Returns true when defaultNamespaces are set

Returns
boolean

Definition at line 182 of file Validate.php.

183  {
184  return (!empty(self::$_defaultNamespaces));
185  }

◆ is()

static is (   $value,
  $classBaseName,
array  $args = array(),
  $namespaces = array() 
)
static
Parameters
mixed$value
string$classBaseName
array$argsOPTIONAL
mixed$namespacesOPTIONAL
Returns
boolean
Exceptions
Zend_Validate_Exception

Definition at line 195 of file Validate.php.

196  {
197  $namespaces = array_merge((array) $namespaces, self::$_defaultNamespaces, array('Zend_Validate'));
198  $className = ucfirst($classBaseName);
199  try {
200  if (!class_exists($className, false)) {
201  #require_once 'Zend/Loader.php';
202  foreach($namespaces as $namespace) {
203  $class = $namespace . '_' . $className;
204  $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
205  if (Zend_Loader::isReadable($file)) {
207  $className = $class;
208  break;
209  }
210  }
211  }
212 
213  $class = new ReflectionClass($className);
214  if ($class->implementsInterface('Zend_Validate_Interface')) {
215  if ($class->hasMethod('__construct')) {
216  $keys = array_keys($args);
217  $numeric = false;
218  foreach($keys as $key) {
219  if (is_numeric($key)) {
220  $numeric = true;
221  break;
222  }
223  }
224 
225  if ($numeric) {
226  $object = $class->newInstanceArgs($args);
227  } else {
228  $object = $class->newInstance($args);
229  }
230  } else {
231  $object = $class->newInstance();
232  }
233 
234  return $object->isValid($value);
235  }
236  } catch (Zend_Validate_Exception $ze) {
237  // if there is an exception while validating throw it
238  throw $ze;
239  } catch (Exception $e) {
240  // fallthrough and continue for missing validation classes
241  }
242 
243  #require_once 'Zend/Validate/Exception.php';
244  throw new Zend_Validate_Exception("Validate class not found from basename '$classBaseName'");
245  }
static loadClass($class, $dirs=null)
Definition: Loader.php:52
static isReadable($filename)
Definition: Loader.php:162
$_option $_optionId $class
Definition: date.phtml:13
$value
Definition: gender.phtml:16
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

◆ isValid()

isValid (   $value)

Returns true if and only if $value passes all validations in the chain

Validators are run in the order in which they were added to the chain (FIFO).

Parameters
mixed$value
Returns
boolean

Implements Zend_Validate_Interface.

Definition at line 91 of file Validate.php.

92  {
93  $this->_messages = array();
94  $this->_errors = array();
95  $result = true;
96  foreach ($this->_validators as $element) {
97  $validator = $element['instance'];
98  if ($validator->isValid($value)) {
99  continue;
100  }
101  $result = false;
102  $messages = $validator->getMessages();
103  $this->_messages = array_merge($this->_messages, $messages);
104  $this->_errors = array_merge($this->_errors, array_keys($messages));
105  if ($element['breakChainOnFailure']) {
106  break;
107  }
108  }
109  return $result;
110  }
$value
Definition: gender.phtml:16
$element
Definition: element.phtml:12

◆ setDefaultNamespaces()

static setDefaultNamespaces (   $namespace)
static

Sets new default namespaces

Parameters
array | string$namespace
Returns
null

Definition at line 153 of file Validate.php.

154  {
155  if (!is_array($namespace)) {
156  $namespace = array((string) $namespace);
157  }
158 
159  self::$_defaultNamespaces = $namespace;
160  }

◆ setDefaultTranslator()

static setDefaultTranslator (   $translator = null)
static

Sets a default translation object for all validation objects

Parameters
Zend_Translate | Zend_Translate_Adapter | null$translator

Definition at line 285 of file Validate.php.

286  {
287  #require_once 'Zend/Validate/Abstract.php';
289  }
static setDefaultTranslator($translator=null)
Definition: Abstract.php:398

◆ setMessageLength()

static setMessageLength (   $length = -1)
static

Sets the maximum allowed message length

Parameters
integer$length

Definition at line 263 of file Validate.php.

264  {
265  #require_once 'Zend/Validate/Abstract.php';
267  }
static setMessageLength($length=-1)
Definition: Abstract.php:479

Field Documentation

◆ $_defaultNamespaces

$_defaultNamespaces = array()
staticprotected

Definition at line 54 of file Validate.php.

◆ $_errors

$_errors = array()
protected

Definition at line 62 of file Validate.php.

◆ $_messages

$_messages = array()
protected

Definition at line 47 of file Validate.php.

◆ $_validators

$_validators = array()
protected

Definition at line 40 of file Validate.php.


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