Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
zendframework1
library
Zend
Validate
NotEmpty.php
Go to the documentation of this file.
1
<?php
25
#require_once 'Zend/Validate/Abstract.php';
26
33
class
Zend_Validate_NotEmpty
extends
Zend_Validate_Abstract
34
{
35
const
BOOLEAN
= 1;
36
const
INTEGER
= 2;
37
const
FLOAT
= 4;
38
const
STRING
= 8;
39
const
ZERO
= 16;
40
const
EMPTY_ARRAY
= 32;
41
const
NULL
= 64;
42
const
PHP
= 127;
43
const
SPACE
= 128;
44
const
OBJECT
= 256;
45
const
OBJECT_STRING
= 512;
46
const
OBJECT_COUNT
= 1024;
47
const
ALL
= 2047;
48
49
const
INVALID
=
'notEmptyInvalid'
;
50
const
IS_EMPTY
=
'isEmpty'
;
51
52
protected
$_constants
= array(
53
self::BOOLEAN =>
'boolean'
,
54
self::INTEGER =>
'integer'
,
55
self::FLOAT =>
'float'
,
56
self::STRING =>
'string'
,
57
self::ZERO =>
'zero'
,
58
self::EMPTY_ARRAY =>
'array'
,
59
self::NULL =>
'null'
,
60
self::PHP =>
'php'
,
61
self::SPACE =>
'space'
,
62
self::OBJECT =>
'object'
,
63
self::OBJECT_STRING =>
'objectstring'
,
64
self::OBJECT_COUNT =>
'objectcount'
,
65
self::ALL =>
'all'
,
66
);
67
71
protected
$_messageTemplates
= array(
72
self::IS_EMPTY =>
"Value is required and can't be empty"
,
73
self::INVALID =>
"Invalid type given. String, integer, float, boolean or array expected"
,
74
);
75
81
protected
$_type
= 493;
82
88
public
function
__construct
(
$options
=
null
)
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
}
106
112
public
function
getType
()
113
{
114
return
$this->_type
;
115
}
116
124
public
function
setType
(
$type
=
null
)
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
}
149
158
public
function
isValid
(
$value
)
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) {
172
$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) {
183
$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) {
225
$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
}
279
}
Zend_Validate_NotEmpty\getType
getType()
Definition:
NotEmpty.php:112
Zend_Validate_NotEmpty\STRING
const STRING
Definition:
NotEmpty.php:38
Zend_Validate_NotEmpty\OBJECT_STRING
const OBJECT_STRING
Definition:
NotEmpty.php:45
Zend_Validate_NotEmpty\ZERO
const ZERO
Definition:
NotEmpty.php:39
Zend_Validate_NotEmpty\FLOAT
const FLOAT
Definition:
NotEmpty.php:37
Zend_Validate_NotEmpty\setType
setType($type=null)
Definition:
NotEmpty.php:124
Zend_Validate_NotEmpty\PHP
const PHP
Definition:
NotEmpty.php:42
Zend_Validate_NotEmpty\__construct
__construct($options=null)
Definition:
NotEmpty.php:88
Zend_Validate_NotEmpty
Definition:
NotEmpty.php:33
Zend_Validate_Abstract\_error
_error($messageKey, $value=null)
Definition:
Abstract.php:284
$type
$type
Definition:
item.phtml:13
Zend_Validate_NotEmpty\EMPTY_ARRAY
const EMPTY_ARRAY
Definition:
NotEmpty.php:40
$value
$value
Definition:
gender.phtml:16
Zend_Validate_Abstract
Definition:
Abstract.php:33
Zend_Validate_NotEmpty\$_messageTemplates
$_messageTemplates
Definition:
NotEmpty.php:71
Zend_Validate_NotEmpty\NULL
const NULL
Definition:
NotEmpty.php:41
Zend_Validate_Abstract\_setValue
_setValue($value)
Definition:
Abstract.php:303
Zend_Validate_NotEmpty\OBJECT
const OBJECT
Definition:
NotEmpty.php:44
Zend_Validate_NotEmpty\SPACE
const SPACE
Definition:
NotEmpty.php:43
Zend_Validate_NotEmpty\isValid
isValid($value)
Definition:
NotEmpty.php:158
Zend_Validate_NotEmpty\BOOLEAN
const BOOLEAN
Definition:
NotEmpty.php:35
Zend_Config
Zend_Validate_NotEmpty\$_type
$_type
Definition:
NotEmpty.php:81
Zend_Validate_Exception
Definition:
Exception.php:33
Zend_Validate_NotEmpty\IS_EMPTY
const IS_EMPTY
Definition:
NotEmpty.php:50
Zend_Validate_NotEmpty\$_constants
$_constants
Definition:
NotEmpty.php:52
$options
$options
Definition:
multiple_mixed_products.php:29
Zend_Validate_NotEmpty\ALL
const ALL
Definition:
NotEmpty.php:47
Zend_Validate_NotEmpty\INTEGER
const INTEGER
Definition:
NotEmpty.php:36
Zend_Validate_NotEmpty\OBJECT_COUNT
const OBJECT_COUNT
Definition:
NotEmpty.php:46
Zend_Validate_NotEmpty\INVALID
const INVALID
Definition:
NotEmpty.php:49