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

Public Member Functions

 __construct ($options)
 
 getHaystack ()
 
 setHaystack (array $haystack)
 
 getStrict ()
 
 setStrict ($strict)
 
 getRecursive ()
 
 setRecursive ($recursive)
 
 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 NOT_IN_ARRAY = 'notInArray'
 

Protected Attributes

 $_messageTemplates
 
 $_haystack
 
 $_strict = false
 
 $_recursive = false
 
- 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 InArray.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options)

Sets validator options

Parameters
array | Zend_Config$optionsValidator options
Exceptions
Zend_Validate_Exception

Definition at line 71 of file InArray.php.

72  {
73  if ($options instanceof Zend_Config) {
74  $options = $options->toArray();
75  } else if (!is_array($options)) {
76  #require_once 'Zend/Validate/Exception.php';
77  throw new Zend_Validate_Exception('Array expected as parameter');
78  } else {
79  $count = func_num_args();
80  $temp = array();
81  if ($count > 1) {
82  $temp['haystack'] = func_get_arg(0);
83  $temp['strict'] = func_get_arg(1);
84  $options = $temp;
85  } else {
86  $temp = func_get_arg(0);
87  if (!array_key_exists('haystack', $options)) {
88  $options = array();
89  $options['haystack'] = $temp;
90  } else {
91  $options = $temp;
92  }
93  }
94  }
95 
96  $this->setHaystack($options['haystack']);
97  if (array_key_exists('strict', $options)) {
98  $this->setStrict($options['strict']);
99  }
100 
101  if (array_key_exists('recursive', $options)) {
102  $this->setRecursive($options['recursive']);
103  }
104  }
setHaystack(array $haystack)
Definition: InArray.php:122
$count
Definition: recent.phtml:13
setRecursive($recursive)
Definition: InArray.php:166

Member Function Documentation

◆ getHaystack()

getHaystack ( )

Returns the haystack option

Returns
mixed

Definition at line 111 of file InArray.php.

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

◆ getRecursive()

getRecursive ( )

Returns the recursive option

Returns
boolean

Definition at line 155 of file InArray.php.

156  {
157  return $this->_recursive;
158  }

◆ getStrict()

getStrict ( )

Returns the strict option

Returns
boolean

Definition at line 133 of file InArray.php.

134  {
135  return $this->_strict;
136  }

◆ isValid()

isValid (   $value)

Defined by Zend_Validate_Interface

Returns true if and only if $value is contained in the haystack option. If the strict option is true, then the type of $value is also checked.

Parameters
mixed$value
Returns
boolean

Implements Zend_Validate_Interface.

Definition at line 181 of file InArray.php.

182  {
183  $this->_setValue($value);
184  if ($this->getRecursive()) {
185  $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->_haystack));
186  foreach($iterator as $element) {
187  if ($this->_strict) {
188  if ($element === $value) {
189  return true;
190  }
191  } else if ($element == $value) {
192  return true;
193  }
194  }
195  } else {
196  if (in_array($value, $this->_haystack, $this->_strict)) {
197  return true;
198  }
199  }
200 
201  $this->_error(self::NOT_IN_ARRAY);
202  return false;
203  }
_error($messageKey, $value=null)
Definition: Abstract.php:284
$value
Definition: gender.phtml:16
$element
Definition: element.phtml:12

◆ setHaystack()

setHaystack ( array  $haystack)

Sets the haystack option

Parameters
mixed$haystack
Returns
Zend_Validate_InArray Provides a fluent interface

Definition at line 122 of file InArray.php.

123  {
124  $this->_haystack = $haystack;
125  return $this;
126  }

◆ setRecursive()

setRecursive (   $recursive)

Sets the recursive option

Parameters
boolean$recursive
Returns
Zend_Validate_InArray Provides a fluent interface

Definition at line 166 of file InArray.php.

167  {
168  $this->_recursive = (boolean) $recursive;
169  return $this;
170  }

◆ setStrict()

setStrict (   $strict)

Sets the strict option

Parameters
boolean$strict
Returns
Zend_Validate_InArray Provides a fluent interface

Definition at line 144 of file InArray.php.

145  {
146  $this->_strict = (boolean) $strict;
147  return $this;
148  }

Field Documentation

◆ $_haystack

$_haystack
protected

Definition at line 49 of file InArray.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::NOT_IN_ARRAY => "'%value%' was not found in the haystack",
)

Definition at line 40 of file InArray.php.

◆ $_recursive

$_recursive = false
protected

Definition at line 63 of file InArray.php.

◆ $_strict

$_strict = false
protected

Definition at line 56 of file InArray.php.

◆ NOT_IN_ARRAY

const NOT_IN_ARRAY = 'notInArray'

Definition at line 35 of file InArray.php.


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