Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Alnum.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Validate/Abstract.php';
26 
34 {
35  const INVALID = 'alnumInvalid';
36  const NOT_ALNUM = 'notAlnum';
37  const STRING_EMPTY = 'alnumStringEmpty';
38 
46 
52  protected static $_filter = null;
53 
59  protected $_messageTemplates = array(
60  self::INVALID => "Invalid type given. String, integer or float expected",
61  self::NOT_ALNUM => "'%value%' contains characters which are non alphabetic and no digits",
62  self::STRING_EMPTY => "'%value%' is an empty string",
63  );
64 
70  public function __construct($allowWhiteSpace = false)
71  {
72  if ($allowWhiteSpace instanceof Zend_Config) {
74  }
75 
76  if (is_array($allowWhiteSpace)) {
77  if (array_key_exists('allowWhiteSpace', $allowWhiteSpace)) {
78  $allowWhiteSpace = $allowWhiteSpace['allowWhiteSpace'];
79  } else {
80  $allowWhiteSpace = false;
81  }
82  }
83 
84  $this->allowWhiteSpace = (boolean) $allowWhiteSpace;
85  }
86 
92  public function getAllowWhiteSpace()
93  {
95  }
96 
104  {
105  $this->allowWhiteSpace = (boolean) $allowWhiteSpace;
106  return $this;
107  }
108 
117  public function isValid($value)
118  {
119  if (!is_string($value) && !is_int($value) && !is_float($value)) {
120  $this->_error(self::INVALID);
121  return false;
122  }
123 
124  $this->_setValue($value);
125 
126  if ('' === $value) {
127  $this->_error(self::STRING_EMPTY);
128  return false;
129  }
130 
131  if (null === self::$_filter) {
135  #require_once 'Zend/Filter/Alnum.php';
136  self::$_filter = new Zend_Filter_Alnum();
137  }
138 
139  self::$_filter->allowWhiteSpace = $this->allowWhiteSpace;
140 
141  if ($value != self::$_filter->filter($value)) {
142  $this->_error(self::NOT_ALNUM);
143  return false;
144  }
145 
146  return true;
147  }
148 
149 }
isValid($value)
Definition: Alnum.php:117
__construct($allowWhiteSpace=false)
Definition: Alnum.php:70
_error($messageKey, $value=null)
Definition: Abstract.php:284
$value
Definition: gender.phtml:16
static $_filter
Definition: Alnum.php:52
setAllowWhiteSpace($allowWhiteSpace)
Definition: Alnum.php:103
const STRING_EMPTY
Definition: Alnum.php:37