PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / libs / Zend / Validate / NotEmpty.php
matomo / app / libs / Zend / Validate Last commit date
File 6 years ago Hostname 6 years ago Abstract.php 6 years ago Alnum.php 6 years ago Alpha.php 6 years ago Between.php 6 years ago Callback.php 6 years ago Ccnum.php 6 years ago CreditCard.php 6 years ago Date.php 6 years ago Digits.php 6 years ago Exception.php 6 years ago Float.php 6 years ago GreaterThan.php 6 years ago Hex.php 6 years ago Hostname.php 6 years ago Iban.php 6 years ago Identical.php 6 years ago InArray.php 6 years ago Int.php 6 years ago Interface.php 6 years ago Ip.php 6 years ago Isbn.php 6 years ago LessThan.php 6 years ago NotEmpty.php 6 years ago PostCode.php 6 years ago Regex.php 6 years ago StringLength.php 6 years ago
NotEmpty.php
280 lines
1 <?php
2 /**
3 * Zend Framework
4 *
5 * LICENSE
6 *
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
14 *
15 * @category Zend
16 * @package Zend_Validate
17 * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
19 * @version $Id: NotEmpty.php 23775 2011-03-01 17:25:24Z ralph $
20 */
21
22 /**
23 * @see Zend_Validate_Abstract
24 */
25 // require_once 'Zend/Validate/Abstract.php';
26
27 /**
28 * @category Zend
29 * @package Zend_Validate
30 * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
31 * @license http://framework.zend.com/license/new-bsd New BSD License
32 */
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
68 /**
69 * @var array
70 */
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
76 /**
77 * Internal type to detect
78 *
79 * @var integer
80 */
81 protected $_type = 493;
82
83 /**
84 * Constructor
85 *
86 * @param string|array|Zend_Config $options OPTIONAL
87 */
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
107 /**
108 * Returns the set types
109 *
110 * @return array
111 */
112 public function getType()
113 {
114 return $this->_type;
115 }
116
117 /**
118 * Set the types
119 *
120 * @param integer|array $type
121 * @throws Zend_Validate_Exception
122 * @return Zend_Validate_NotEmpty
123 */
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
150 /**
151 * Defined by Zend_Validate_Interface
152 *
153 * Returns true if and only if $value is not an empty value.
154 *
155 * @param string $value
156 * @return boolean
157 */
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 }
280