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

Public Member Functions

 __construct ($options=null)
 
 getType ()
 
 setType ($type=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 BOOLEAN = 1
 
const INTEGER = 2
 
const FLOAT = 4
 
const STRING = 8
 
const ZERO = 16
 
const EMPTY_ARRAY = 32
 
const NULL = 64
 
const PHP = 127
 
const SPACE = 128
 
const OBJECT = 256
 
const OBJECT_STRING = 512
 
const OBJECT_COUNT = 1024
 
const ALL = 2047
 
const INVALID = 'notEmptyInvalid'
 
const IS_EMPTY = 'isEmpty'
 

Protected Attributes

 $_constants
 
 $_messageTemplates
 
 $_type = 493
 
- 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 NotEmpty.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = null)

Constructor

Parameters
string | array | Zend_Config$optionsOPTIONAL

Definition at line 88 of file NotEmpty.php.

89  {
90  if ($options instanceof Zend_Config) {
91  $options = $options->toArray();
92  } else if (!is_array($options)) {
93  $options = func_get_args();
94  $temp = array();
95  if (!empty($options)) {
96  $temp['type'] = array_shift($options);
97  }
98 
99  $options = $temp;
100  }
101 
102  if (is_array($options) && array_key_exists('type', $options)) {
103  $this->setType($options['type']);
104  }
105  }
setType($type=null)
Definition: NotEmpty.php:124

Member Function Documentation

◆ getType()

getType ( )

Returns the set types

Returns
array

Definition at line 112 of file NotEmpty.php.

113  {
114  return $this->_type;
115  }

◆ isValid()

isValid (   $value)

Defined by Zend_Validate_Interface

Returns true if and only if $value is not an empty value.

Parameters
string$value
Returns
boolean

Implements Zend_Validate_Interface.

Definition at line 158 of file NotEmpty.php.

159  {
160  if ($value !== null && !is_string($value) && !is_int($value) && !is_float($value) &&
161  !is_bool($value) && !is_array($value) && !is_object($value)) {
162  $this->_error(self::INVALID);
163  return false;
164  }
165 
166  $type = $this->getType();
167  $this->_setValue($value);
168  $object = false;
169 
170  // OBJECT_COUNT (countable object)
171  if ($type >= self::OBJECT_COUNT) {
173  $object = true;
174 
175  if (is_object($value) && ($value instanceof Countable) && (count($value) == 0)) {
176  $this->_error(self::IS_EMPTY);
177  return false;
178  }
179  }
180 
181  // OBJECT_STRING (object's toString)
182  if ($type >= self::OBJECT_STRING) {
184  $object = true;
185 
186  if ((is_object($value) && (!method_exists($value, '__toString'))) ||
187  (is_object($value) && (method_exists($value, '__toString')) && (((string) $value) == ""))) {
188  $this->_error(self::IS_EMPTY);
189  return false;
190  }
191  }
192 
193  // OBJECT (object)
194  if ($type >= self::OBJECT) {
195  $type -= self::OBJECT;
196  // fall trough, objects are always not empty
197  } else if ($object === false) {
198  // object not allowed but object given -> return false
199  if (is_object($value)) {
200  $this->_error(self::IS_EMPTY);
201  return false;
202  }
203  }
204 
205  // SPACE (' ')
206  if ($type >= self::SPACE) {
207  $type -= self::SPACE;
208  if (is_string($value) && (preg_match('/^\s+$/s', $value))) {
209  $this->_error(self::IS_EMPTY);
210  return false;
211  }
212  }
213 
214  // NULL (null)
215  if ($type >= self::NULL) {
216  $type -= self::NULL;
217  if ($value === null) {
218  $this->_error(self::IS_EMPTY);
219  return false;
220  }
221  }
222 
223  // EMPTY_ARRAY (array())
224  if ($type >= self::EMPTY_ARRAY) {
226  if (is_array($value) && ($value == array())) {
227  $this->_error(self::IS_EMPTY);
228  return false;
229  }
230  }
231 
232  // ZERO ('0')
233  if ($type >= self::ZERO) {
234  $type -= self::ZERO;
235  if (is_string($value) && ($value == '0')) {
236  $this->_error(self::IS_EMPTY);
237  return false;
238  }
239  }
240 
241  // STRING ('')
242  if ($type >= self::STRING) {
243  $type -= self::STRING;
244  if (is_string($value) && ($value == '')) {
245  $this->_error(self::IS_EMPTY);
246  return false;
247  }
248  }
249 
250  // FLOAT (0.0)
251  if ($type >= self::FLOAT) {
252  $type -= self::FLOAT;
253  if (is_float($value) && ($value == 0.0)) {
254  $this->_error(self::IS_EMPTY);
255  return false;
256  }
257  }
258 
259  // INTEGER (0)
260  if ($type >= self::INTEGER) {
261  $type -= self::INTEGER;
262  if (is_int($value) && ($value == 0)) {
263  $this->_error(self::IS_EMPTY);
264  return false;
265  }
266  }
267 
268  // BOOLEAN (false)
269  if ($type >= self::BOOLEAN) {
270  $type -= self::BOOLEAN;
271  if (is_bool($value) && ($value == false)) {
272  $this->_error(self::IS_EMPTY);
273  return false;
274  }
275  }
276 
277  return true;
278  }
_error($messageKey, $value=null)
Definition: Abstract.php:284
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16

◆ setType()

setType (   $type = null)

Set the types

Parameters
integer | array$type
Exceptions
Zend_Validate_Exception
Returns
Zend_Validate_NotEmpty

Definition at line 124 of file NotEmpty.php.

125  {
126  if (is_array($type)) {
127  $detected = 0;
128  foreach($type as $value) {
129  if (is_int($value)) {
130  $detected += $value;
131  } else if (in_array($value, $this->_constants)) {
132  $detected += array_search($value, $this->_constants);
133  }
134  }
135 
136  $type = $detected;
137  } else if (is_string($type) && in_array($type, $this->_constants)) {
138  $type = array_search($type, $this->_constants);
139  }
140 
141  if (!is_int($type) || ($type < 0) || ($type > self::ALL)) {
142  #require_once 'Zend/Validate/Exception.php';
143  throw new Zend_Validate_Exception('Unknown type');
144  }
145 
146  $this->_type = $type;
147  return $this;
148  }
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16

Field Documentation

◆ $_constants

$_constants
protected
Initial value:
= array(
self::BOOLEAN => 'boolean',
self::INTEGER => 'integer',
self::FLOAT => 'float',
self::STRING => 'string',
self::ZERO => 'zero',
self::EMPTY_ARRAY => 'array',
self::NULL => 'null',
self::PHP => 'php',
self::SPACE => 'space',
self::OBJECT => 'object',
self::OBJECT_STRING => 'objectstring',
self::OBJECT_COUNT => 'objectcount',
self::ALL => 'all',
)

Definition at line 52 of file NotEmpty.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::IS_EMPTY => "Value is required and can't be empty",
self::INVALID => "Invalid type given. String, integer, float, boolean or array expected",
)

Definition at line 71 of file NotEmpty.php.

◆ $_type

$_type = 493
protected

Definition at line 81 of file NotEmpty.php.

◆ ALL

const ALL = 2047

Definition at line 47 of file NotEmpty.php.

◆ BOOLEAN

const BOOLEAN = 1

Definition at line 35 of file NotEmpty.php.

◆ EMPTY_ARRAY

const EMPTY_ARRAY = 32

Definition at line 40 of file NotEmpty.php.

◆ FLOAT

const FLOAT = 4

Definition at line 37 of file NotEmpty.php.

◆ INTEGER

const INTEGER = 2

Definition at line 36 of file NotEmpty.php.

◆ INVALID

const INVALID = 'notEmptyInvalid'

Definition at line 49 of file NotEmpty.php.

◆ IS_EMPTY

const IS_EMPTY = 'isEmpty'

Definition at line 50 of file NotEmpty.php.

◆ NULL

const NULL = 64

Definition at line 41 of file NotEmpty.php.

◆ OBJECT

const OBJECT = 256

Definition at line 44 of file NotEmpty.php.

◆ OBJECT_COUNT

const OBJECT_COUNT = 1024

Definition at line 46 of file NotEmpty.php.

◆ OBJECT_STRING

const OBJECT_STRING = 512

Definition at line 45 of file NotEmpty.php.

◆ PHP

const PHP = 127

Definition at line 42 of file NotEmpty.php.

◆ SPACE

const SPACE = 128

Definition at line 43 of file NotEmpty.php.

◆ STRING

const STRING = 8

Definition at line 38 of file NotEmpty.php.

◆ ZERO

const ZERO = 16

Definition at line 39 of file NotEmpty.php.


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