1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright (c) 2016-present Ganbaro Digital Ltd |
5
|
|
|
* All rights reserved. |
6
|
|
|
* |
7
|
|
|
* Redistribution and use in source and binary forms, with or without |
8
|
|
|
* modification, are permitted provided that the following conditions |
9
|
|
|
* are met: |
10
|
|
|
* |
11
|
|
|
* * Redistributions of source code must retain the above copyright |
12
|
|
|
* notice, this list of conditions and the following disclaimer. |
13
|
|
|
* |
14
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
15
|
|
|
* notice, this list of conditions and the following disclaimer in |
16
|
|
|
* the documentation and/or other materials provided with the |
17
|
|
|
* distribution. |
18
|
|
|
* |
19
|
|
|
* * Neither the names of the copyright holders nor the names of his |
20
|
|
|
* contributors may be used to endorse or promote products derived |
21
|
|
|
* from this software without specific prior written permission. |
22
|
|
|
* |
23
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
24
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
25
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
26
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
27
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
28
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
29
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
30
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
31
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
32
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
33
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
34
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
35
|
|
|
* |
36
|
|
|
* @category Libraries |
37
|
|
|
* @package MissingBits/Types |
38
|
|
|
* @author Stuart Herbert <[email protected]> |
39
|
|
|
* @copyright 2016-present Ganbaro Digital Ltd www.ganbarodigital.com |
40
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
41
|
|
|
* @link http://ganbarodigital.github.io/php-the-missing-bits |
42
|
|
|
*/ |
43
|
|
|
|
44
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsArray; |
45
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsAssignable; |
46
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsBoolean; |
47
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsCallable; |
48
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsList; |
49
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsListyObject; |
50
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsCompatibleWith; |
51
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsDefinedClass; |
52
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsDefinedInterface; |
53
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsDefinedObjectType; |
54
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsDefinedTrait; |
55
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsDouble; |
56
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsEmpty; |
57
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsIndexable; |
58
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsInteger; |
59
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsLogical; |
60
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsNull; |
61
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsNumeric; |
62
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsObject; |
63
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsObjectOfType; |
64
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsPcreRegex; |
65
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsResource; |
66
|
|
|
use GanbaroDigital\MissingBits\TypeChecks\IsStringy; |
67
|
|
|
use GanbaroDigital\MissingBits\TypeInspectors\GetArrayTypes; |
68
|
|
|
use GanbaroDigital\MissingBits\TypeInspectors\GetClassTraits; |
69
|
|
|
use GanbaroDigital\MissingBits\TypeInspectors\GetClassTypes; |
70
|
|
|
use GanbaroDigital\MissingBits\TypeInspectors\GetNamespace; |
71
|
|
|
use GanbaroDigital\MissingBits\TypeInspectors\GetNumericType; |
72
|
|
|
use GanbaroDigital\MissingBits\TypeInspectors\GetObjectTypes; |
73
|
|
|
use GanbaroDigital\MissingBits\TypeInspectors\GetPrintableType; |
74
|
|
|
use GanbaroDigital\MissingBits\TypeInspectors\GetStrictTypes; |
75
|
|
|
use GanbaroDigital\MissingBits\TypeInspectors\GetStringDuckTypes; |
76
|
|
|
use GanbaroDigital\MissingBits\TypeInspectors\GetStringTypes; |
77
|
|
|
use GanbaroDigital\MissingBits\TypeInspectors\StripNamespace; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* do we have something that is an array? |
81
|
|
|
* |
82
|
|
|
* by array, we mean something that you can pass to any of PHP's |
83
|
|
|
* array_xxx() functions |
84
|
|
|
* |
85
|
|
|
* @param mixed $fieldOrVar |
86
|
|
|
* the item to be checked |
87
|
|
|
* @return bool |
88
|
|
|
* TRUE if the item is an array |
89
|
|
|
* FALSE otherwise |
90
|
|
|
*/ |
91
|
|
|
function check_is_array($fieldOrVar) |
92
|
|
|
{ |
93
|
|
|
return IsArray::check($fieldOrVar); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* is every entry in $list an array? |
98
|
|
|
* |
99
|
|
|
* by array, we mean something that you can pass to any of PHP's |
100
|
|
|
* array_xxx() functions |
101
|
|
|
* |
102
|
|
|
* @param mixed $list |
103
|
|
|
* the list of items to be checked |
104
|
|
|
* @return bool |
105
|
|
|
* TRUE if every item in $list is an array |
106
|
|
|
* FALSE otherwise |
107
|
|
|
*/ |
108
|
|
|
function check_is_array_list($list) |
109
|
|
|
{ |
110
|
|
|
return IsArray::checkList($list); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* do we have something that can be used with PHP's object notation |
115
|
|
|
* for assigning the value of variables? |
116
|
|
|
* |
117
|
|
|
* @param mixed $fieldOrVar |
118
|
|
|
* the item to examine |
119
|
|
|
* @return bool |
120
|
|
|
* true if the item is compatible |
121
|
|
|
* false otherwise |
122
|
|
|
*/ |
123
|
|
|
function check_is_assignable($fieldOrVar) |
124
|
|
|
{ |
125
|
|
|
return IsAssignable::check($fieldOrVar); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* can every item in $list be used with PHP's object notation for |
130
|
|
|
* assigning the valule of variables? |
131
|
|
|
* |
132
|
|
|
* @param mixed $list |
133
|
|
|
* the list to examine |
134
|
|
|
* @return bool |
135
|
|
|
* true if every item in $list is compatible |
136
|
|
|
* false otherwise |
137
|
|
|
*/ |
138
|
|
|
function check_is_assignable_list($list) |
139
|
|
|
{ |
140
|
|
|
return IsAssignable::checkList($list); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* do we have something that is a boolean? |
145
|
|
|
* |
146
|
|
|
* @param mixed $fieldOrVar |
147
|
|
|
* the item to be checked |
148
|
|
|
* @return bool |
149
|
|
|
* TRUE if the item is a boolean |
150
|
|
|
* FALSE otherwise |
151
|
|
|
*/ |
152
|
|
|
function check_is_boolean($fieldOrVar) |
153
|
|
|
{ |
154
|
|
|
return IsBoolean::check($fieldOrVar); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* do we have a list of booleans? |
159
|
|
|
* |
160
|
|
|
* @param mixed $list |
161
|
|
|
* the list to be checked |
162
|
|
|
* @return bool |
163
|
|
|
* TRUE if every item in the list is a boolean |
164
|
|
|
* FALSE otherwise |
165
|
|
|
*/ |
166
|
|
|
function check_is_boolean_list($list) |
167
|
|
|
{ |
168
|
|
|
return IsBoolean::checkList($list); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* do we have something that can be used as a PHP callable? |
173
|
|
|
* |
174
|
|
|
* @param mixed $fieldOrVar |
175
|
|
|
* the value to check |
176
|
|
|
* @return bool |
177
|
|
|
* TRUE if $fieldOrVar is a callable |
178
|
|
|
* FALSE otherwise |
179
|
|
|
*/ |
180
|
|
|
function check_is_callable($fieldOrVar) |
181
|
|
|
{ |
182
|
|
|
return IsCallable::check($fieldOrVar); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* is every entry in $list a callable? |
187
|
|
|
* |
188
|
|
|
* @param mixed $list |
189
|
|
|
* the list of items to be checked |
190
|
|
|
* @return bool |
191
|
|
|
* TRUE if every item in $list is a callable |
192
|
|
|
* FALSE otherwise |
193
|
|
|
*/ |
194
|
|
|
function check_is_callable_list($list) |
195
|
|
|
{ |
196
|
|
|
return IsCallable::checkList($list); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* is $fieldOrVar compatible with $expectedType? |
201
|
|
|
* |
202
|
|
|
* @param mixed $fieldOrVar |
203
|
|
|
* the classname or object to check |
204
|
|
|
* @param string|object $expectedType |
205
|
|
|
* the classname or object that we want to check for |
206
|
|
|
* @return bool |
207
|
|
|
* TRUE if $fieldOrVar is compatible |
208
|
|
|
* FALSE otherwise |
209
|
|
|
*/ |
210
|
|
|
function check_is_compatible_with($fieldOrVar, $expectedType) |
211
|
|
|
{ |
212
|
|
|
return IsCompatibleWith::check($fieldOrVar, $expectedType); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* is every entry in $list compatible with $expectedType? |
217
|
|
|
* |
218
|
|
|
* @param mixed $list |
219
|
|
|
* the list of items to be checked |
220
|
|
|
* @param string $expectedType |
221
|
|
|
* the class or interface that we want to check against |
222
|
|
|
* @return bool |
223
|
|
|
* TRUE if every item in $list is a classname or object of |
224
|
|
|
* a given type |
225
|
|
|
* FALSE otherwise |
226
|
|
|
*/ |
227
|
|
|
function check_is_compatible_with_list($list, $expectedType) |
228
|
|
|
{ |
229
|
|
|
return IsCompatibleWith::checkList($list, $expectedType); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* do we have the name of a class that has been defined? |
234
|
|
|
* |
235
|
|
|
* @param mixed $fieldOrVar |
236
|
|
|
* the name to check |
237
|
|
|
* @return bool |
238
|
|
|
* TRUE if $fieldOrVar is a class that has been defined |
239
|
|
|
* FALSE otherwise |
240
|
|
|
*/ |
241
|
|
|
function check_is_defined_class($fieldOrVar) |
242
|
|
|
{ |
243
|
|
|
return IsDefinedClass::check($fieldOrVar); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* is every entry in $list a defined class? |
248
|
|
|
* |
249
|
|
|
* @param mixed $list |
250
|
|
|
* the list of items to be checked |
251
|
|
|
* @return bool |
252
|
|
|
* TRUE if every item in $list is a defined class |
253
|
|
|
* FALSE otherwise |
254
|
|
|
*/ |
255
|
|
|
function check_is_defined_class_list($list) |
256
|
|
|
{ |
257
|
|
|
return IsDefinedClass::checkList($list); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* do we have the name of an interface that has been defined? |
262
|
|
|
* |
263
|
|
|
* @param mixed $fieldOrVar |
264
|
|
|
* the name to check |
265
|
|
|
* @return bool |
266
|
|
|
* TRUE if $fieldOrVar is an interface that has been defined |
267
|
|
|
* FALSE otherwise |
268
|
|
|
*/ |
269
|
|
|
function check_is_defined_interface($fieldOrVar) |
270
|
|
|
{ |
271
|
|
|
return IsDefinedInterface::check($fieldOrVar); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* is every entry in $list a defined interface? |
276
|
|
|
* |
277
|
|
|
* @param mixed $list |
278
|
|
|
* the list of items to be checked |
279
|
|
|
* @return bool |
280
|
|
|
* TRUE if every item in $list is a defined interface |
281
|
|
|
* FALSE otherwise |
282
|
|
|
*/ |
283
|
|
|
function check_is_defined_interface_list($list) |
284
|
|
|
{ |
285
|
|
|
return IsDefinedInterface::checkList($list); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* is $fieldOrVar a valid type for an object? |
290
|
|
|
* |
291
|
|
|
* @param mixed $fieldOrVar |
292
|
|
|
* the name to check |
293
|
|
|
* @return bool |
294
|
|
|
* TRUE if $fieldOrVar is a class or interface name |
295
|
|
|
* FALSE otherwise |
296
|
|
|
*/ |
297
|
|
|
function check_is_defined_object_type($fieldOrVar) |
298
|
|
|
{ |
299
|
|
|
return IsDefinedObjectType::check($fieldOrVar); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* is every entry in $list a valid type for an object? |
304
|
|
|
* |
305
|
|
|
* @param mixed $list |
306
|
|
|
* the list of items to be checked |
307
|
|
|
* @return bool |
308
|
|
|
* TRUE if every item in $list is a a valid type for an object |
309
|
|
|
* FALSE otherwise |
310
|
|
|
*/ |
311
|
|
|
function check_is_defined_object_type_list($list) |
312
|
|
|
{ |
313
|
|
|
return IsDefinedObjectType::checkList($list); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* do we have the name of a trait that has been defined? |
318
|
|
|
* |
319
|
|
|
* @param mixed $fieldOrVar |
320
|
|
|
* the name to check |
321
|
|
|
* @return bool |
322
|
|
|
* TRUE if $fieldOrVar is a trait that has been defined |
323
|
|
|
* FALSE otherwise |
324
|
|
|
*/ |
325
|
|
|
function check_is_defined_trait($fieldOrVar) |
326
|
|
|
{ |
327
|
|
|
return IsDefinedTrait::check($fieldOrVar); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* is every entry in $list a defined class? |
332
|
|
|
* |
333
|
|
|
* @param mixed $list |
334
|
|
|
* the list of items to be checked |
335
|
|
|
* @return bool |
336
|
|
|
* TRUE if every item in $list is a defined class |
337
|
|
|
* FALSE otherwise |
338
|
|
|
*/ |
339
|
|
|
function check_is_defined_trait_list($list) |
340
|
|
|
{ |
341
|
|
|
return IsDefinedTrait::checkList($list); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* do we have something that is a double? |
346
|
|
|
* |
347
|
|
|
* @param mixed $fieldOrVar |
348
|
|
|
* the item to be checked |
349
|
|
|
* @return bool |
350
|
|
|
* TRUE if the item is a double, or can be used as a double |
351
|
|
|
* FALSE otherwise |
352
|
|
|
*/ |
353
|
|
|
function check_is_double($fieldOrVar) |
354
|
|
|
{ |
355
|
|
|
return IsDouble::check($fieldOrVar); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* is every entry in $list a double? |
360
|
|
|
* |
361
|
|
|
* @param mixed $list |
362
|
|
|
* the list of items to be checked |
363
|
|
|
* @return bool |
364
|
|
|
* TRUE if every item in $list is a defined class |
365
|
|
|
* FALSE otherwise |
366
|
|
|
*/ |
367
|
|
|
function check_is_double_list($list) |
368
|
|
|
{ |
369
|
|
|
return IsDouble::checkList($list); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* check if an item is empty |
374
|
|
|
* |
375
|
|
|
* empty means one of: |
376
|
|
|
* - item itself is empty |
377
|
|
|
* - item is a data container, and only contains empty data items |
378
|
|
|
* |
379
|
|
|
* BE AWARE that this check WILL descend down into the contents of $fieldOrVar |
380
|
|
|
* until it finds the first piece of non-empty data. This has the potential |
381
|
|
|
* to be computationally expensive. |
382
|
|
|
* |
383
|
|
|
* @param mixed $fieldOrVar |
384
|
|
|
* the item to check |
385
|
|
|
* @return bool |
386
|
|
|
* TRUE if the item is empty |
387
|
|
|
* FALSE otherwise |
388
|
|
|
*/ |
389
|
|
|
function check_is_empty($fieldOrVar) |
390
|
|
|
{ |
391
|
|
|
return IsEmpty::check($fieldOrVar); |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* is every entry in $list empty? |
396
|
|
|
* |
397
|
|
|
* @param mixed $list |
398
|
|
|
* the list of items to be checked |
399
|
|
|
* @return bool |
400
|
|
|
* TRUE if every item in $list is empty |
401
|
|
|
* FALSE otherwise |
402
|
|
|
*/ |
403
|
|
|
function check_is_empty_list($list) |
404
|
|
|
{ |
405
|
|
|
return IsEmpty::checkList($list); |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
/** |
409
|
|
|
* is $fieldOrVar something that can be used by PHP code that uses array |
410
|
|
|
* index notation? |
411
|
|
|
* |
412
|
|
|
* @param mixed $fieldOrVar |
413
|
|
|
* the item to examine |
414
|
|
|
* @return bool |
415
|
|
|
* true if the item is compatible |
416
|
|
|
* false otherwise |
417
|
|
|
*/ |
418
|
|
|
function check_is_indexable($fieldOrVar) |
419
|
|
|
{ |
420
|
|
|
return IsIndexable::check($fieldOrVar); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
/** |
424
|
|
|
* is every entry in $list indexable? |
425
|
|
|
* |
426
|
|
|
* @param mixed $list |
427
|
|
|
* the list of items to be checked |
428
|
|
|
* @return bool |
429
|
|
|
* TRUE if every item in $list is indexable |
430
|
|
|
* FALSE otherwise |
431
|
|
|
*/ |
432
|
|
|
function check_is_indexable_list($list) |
433
|
|
|
{ |
434
|
|
|
return IsIndexable::checkList($list); |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
/** |
438
|
|
|
* do we have something that is an integer? |
439
|
|
|
* |
440
|
|
|
* @param mixed $fieldOrVar |
441
|
|
|
* the item to be checked |
442
|
|
|
* @return bool |
443
|
|
|
* TRUE if the item is an integer, or can be used as an integer |
444
|
|
|
* FALSE otherwise |
445
|
|
|
*/ |
446
|
|
|
function check_is_integer($fieldOrVar) |
447
|
|
|
{ |
448
|
|
|
return IsInteger::check($fieldOrVar); |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
/** |
452
|
|
|
* is every entry in $list an integer? |
453
|
|
|
* |
454
|
|
|
* @param mixed $list |
455
|
|
|
* the list of items to be checked |
456
|
|
|
* @return bool |
457
|
|
|
* TRUE if every item in $list is an integer |
458
|
|
|
* FALSE otherwise |
459
|
|
|
*/ |
460
|
|
|
function check_is_integer_list($list) |
461
|
|
|
{ |
462
|
|
|
return IsInteger::checkList($list); |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
/** |
466
|
|
|
* can $list be safely (and sensibly) used in a foreach() loop? |
467
|
|
|
* |
468
|
|
|
* @param mixed $list |
469
|
|
|
* the value to inspect |
470
|
|
|
* @return bool |
471
|
|
|
* TRUE if $list can be used in a foreach() loop |
472
|
|
|
* FALSE otherwise |
473
|
|
|
*/ |
474
|
|
|
function check_is_list($list) |
475
|
|
|
{ |
476
|
|
|
return IsList::check($list); |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* can $list be safely (and sensibly) used in a foreach() loop? |
481
|
|
|
* |
482
|
|
|
* @param object $list |
483
|
|
|
* the value to inspect |
484
|
|
|
* @return bool |
485
|
|
|
* TRUE if $list can be used in a foreach() loop |
486
|
|
|
* FALSE otherwise |
487
|
|
|
*/ |
488
|
|
|
function check_is_listy_object($list) |
489
|
|
|
{ |
490
|
|
|
return IsListyObject::check($list); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
/** |
494
|
|
|
* do we have something that can be used as a boolean value? |
495
|
|
|
* |
496
|
|
|
* @param mixed $fieldOrVar |
497
|
|
|
* the item to be checked |
498
|
|
|
* @return bool |
499
|
|
|
* TRUE if the item can be used as a boolean |
500
|
|
|
* FALSE otherwise |
501
|
|
|
*/ |
502
|
|
|
function check_is_logical($fieldOrVar) |
503
|
|
|
{ |
504
|
|
|
return IsLogical::check($fieldOrVar); |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
/** |
508
|
|
|
* is every entry in $list something that can be used as a boolean value? |
509
|
|
|
* |
510
|
|
|
* @param mixed $list |
511
|
|
|
* the list of items to be checked |
512
|
|
|
* @return bool |
513
|
|
|
* TRUE if every item in $list can be used as a boolean |
514
|
|
|
* FALSE otherwise |
515
|
|
|
*/ |
516
|
|
|
function check_is_logical_list($list) |
517
|
|
|
{ |
518
|
|
|
return IsLogical::checkList($list); |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
/** |
522
|
|
|
* do we have something that is null? |
523
|
|
|
* |
524
|
|
|
* @param mixed $fieldOrVar |
525
|
|
|
* the item to be checked |
526
|
|
|
* @return bool |
527
|
|
|
* TRUE if the item is null |
528
|
|
|
* FALSE otherwise |
529
|
|
|
*/ |
530
|
|
|
function check_is_null($fieldOrVar) |
531
|
|
|
{ |
532
|
|
|
return IsNull::check($fieldOrVar); |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
/** |
536
|
|
|
* is every entry in $list a NULL value? |
537
|
|
|
* |
538
|
|
|
* @param mixed $list |
539
|
|
|
* the list of items to be checked |
540
|
|
|
* @return bool |
541
|
|
|
* TRUE if every item in $list is a NULL value |
542
|
|
|
* FALSE otherwise |
543
|
|
|
*/ |
544
|
|
|
function check_is_null_list($list) |
545
|
|
|
{ |
546
|
|
|
return IsNull::checkList($list); |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
/** |
550
|
|
|
* do we have something that can be used as a number? |
551
|
|
|
* |
552
|
|
|
* NOTE that we don't guarantee an int, a float, or even a base-10 |
553
|
|
|
* number in this check, even though that might be what you're hoping |
554
|
|
|
* for |
555
|
|
|
* |
556
|
|
|
* @param mixed $fieldOrVar |
557
|
|
|
* the item to be checked |
558
|
|
|
* @return bool |
559
|
|
|
* TRUE if the item can be used as a number |
560
|
|
|
* FALSE otherwise |
561
|
|
|
*/ |
562
|
|
|
function check_is_numeric($fieldOrVar) |
563
|
|
|
{ |
564
|
|
|
return IsNumeric::check($fieldOrVar); |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
/** |
568
|
|
|
* is every entry in $list a number of some kind? |
569
|
|
|
* |
570
|
|
|
* @param mixed $list |
571
|
|
|
* the list of items to be checked |
572
|
|
|
* @return bool |
573
|
|
|
* TRUE if every item in $list can be used as a number |
574
|
|
|
* FALSE otherwise |
575
|
|
|
*/ |
576
|
|
|
function check_is_numeric_list($list) |
577
|
|
|
{ |
578
|
|
|
return IsNumeric::checkList($list); |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
/** |
582
|
|
|
* do we have something that is an object? |
583
|
|
|
* |
584
|
|
|
* @param mixed $fieldOrVar |
585
|
|
|
* the item to be checked |
586
|
|
|
* @return bool |
587
|
|
|
* TRUE if the item is an object |
588
|
|
|
* FALSE otherwise |
589
|
|
|
*/ |
590
|
|
|
function check_is_object($fieldOrVar) |
591
|
|
|
{ |
592
|
|
|
return IsObject::check($fieldOrVar); |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
/** |
596
|
|
|
* is every entry in $list an object? |
597
|
|
|
* |
598
|
|
|
* @param mixed $list |
599
|
|
|
* the list of items to be checked |
600
|
|
|
* @return bool |
601
|
|
|
* TRUE if every item in $list is an object |
602
|
|
|
* FALSE otherwise |
603
|
|
|
*/ |
604
|
|
|
function check_is_object_list($list) |
605
|
|
|
{ |
606
|
|
|
return IsObject::checkList($list); |
607
|
|
|
} |
608
|
|
|
|
609
|
|
|
/** |
610
|
|
|
* do we have something that is a specific type of object? |
611
|
|
|
* |
612
|
|
|
* @param mixed $fieldOrVar |
613
|
|
|
* the item to be checked |
614
|
|
|
* @param string $expectedType |
615
|
|
|
* the class or interface that we want to check against |
616
|
|
|
* @return bool |
617
|
|
|
* TRUE if the item is the requested type |
618
|
|
|
* FALSE otherwise |
619
|
|
|
*/ |
620
|
|
|
function check_is_object_of_type($fieldOrVar, $expectedType) |
621
|
|
|
{ |
622
|
|
|
return IsObjectOfType::check($fieldOrVar, $expectedType); |
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
/** |
626
|
|
|
* is every entry in $list an object of a given type? |
627
|
|
|
* |
628
|
|
|
* @param mixed $list |
629
|
|
|
* the list of items to be checked |
630
|
|
|
* @param string $expectedType |
631
|
|
|
* the class or interface that we want to check against |
632
|
|
|
* @return bool |
633
|
|
|
* TRUE if every item in $list is an object of a given type |
634
|
|
|
* FALSE otherwise |
635
|
|
|
*/ |
636
|
|
|
function check_is_object_of_type_list($list, $expectedType) |
637
|
|
|
{ |
638
|
|
|
return IsObjectOfType::checkList($list, $expectedType); |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
/** |
642
|
|
|
* do we have a valid PCRE regex? |
643
|
|
|
* |
644
|
|
|
* @param string $fieldOrVar |
645
|
|
|
* the item to be checked |
646
|
|
|
* @return bool |
647
|
|
|
* TRUE if the item is a valid PCRE regex |
648
|
|
|
* FALSE otherwise |
649
|
|
|
*/ |
650
|
|
|
function check_is_pcre_regex($fieldOrVar) |
651
|
|
|
{ |
652
|
|
|
return IsPcreRegex::check($fieldOrVar); |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
/** |
656
|
|
|
* is every entry in $list a valid PCRE regex? |
657
|
|
|
* |
658
|
|
|
* @param mixed $list |
659
|
|
|
* the list of items to be checked |
660
|
|
|
* @return bool |
661
|
|
|
* TRUE if every item in $list is a valid PCRE regex |
662
|
|
|
* FALSE otherwise |
663
|
|
|
*/ |
664
|
|
|
function check_is_pcre_regex_list($list) |
665
|
|
|
{ |
666
|
|
|
return IsPcreRegex::checkList($list); |
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
/** |
670
|
|
|
* do we have something that is a PHP resource? |
671
|
|
|
* |
672
|
|
|
* @param mixed $fieldOrVar |
673
|
|
|
* the item to be checked |
674
|
|
|
* @return bool |
675
|
|
|
* TRUE if the item is a resource |
676
|
|
|
* FALSE otherwise |
677
|
|
|
*/ |
678
|
|
|
function check_is_resource($fieldOrVar) |
679
|
|
|
{ |
680
|
|
|
return IsResource::check($fieldOrVar); |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
/** |
684
|
|
|
* is every entry in $list a PHP resource? |
685
|
|
|
* |
686
|
|
|
* @param mixed $list |
687
|
|
|
* the list of items to be checked |
688
|
|
|
* @return bool |
689
|
|
|
* TRUE if every item in $list is a PHP resource |
690
|
|
|
* FALSE otherwise |
691
|
|
|
*/ |
692
|
|
|
function check_is_resource_list($list) |
693
|
|
|
{ |
694
|
|
|
return IsResource::checkList($list); |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
/** |
698
|
|
|
* is $item something that PHP will accept as a string? |
699
|
|
|
* |
700
|
|
|
* @param mixed $item |
701
|
|
|
* the variable to examine |
702
|
|
|
* @return bool |
703
|
|
|
* TRUE if PHP will happily use $item as a string |
704
|
|
|
* FALSE otherwise |
705
|
|
|
*/ |
706
|
|
|
function check_is_stringy($item) |
707
|
|
|
{ |
708
|
|
|
return IsStringy::check($item); |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
/** |
712
|
|
|
* get a full list of strict types than an array can satisfy |
713
|
|
|
* |
714
|
|
|
* @param array $item |
715
|
|
|
* the item to examine |
716
|
|
|
* @return string[] |
717
|
|
|
* the array's list of types |
718
|
|
|
*/ |
719
|
|
|
function get_array_types($item) |
720
|
|
|
{ |
721
|
|
|
return GetArrayTypes::from($item); |
722
|
|
|
} |
723
|
|
|
|
724
|
|
|
/** |
725
|
|
|
* get a full list of the traits used by a class or its parents |
726
|
|
|
* |
727
|
|
|
* @param string $item |
728
|
|
|
* the item to examine |
729
|
|
|
* @return string[] |
730
|
|
|
* the class's traits list |
731
|
|
|
*/ |
732
|
|
|
function get_class_traits($item) |
733
|
|
|
{ |
734
|
|
|
return GetClassTraits::from($item); |
735
|
|
|
} |
736
|
|
|
|
737
|
|
|
/** |
738
|
|
|
* get a full list of a class's inheritence hierarchy |
739
|
|
|
* |
740
|
|
|
* @param string $item |
741
|
|
|
* the item to examine |
742
|
|
|
* @return string[] |
743
|
|
|
* the class's inheritence hierarchy |
744
|
|
|
*/ |
745
|
|
|
function get_class_types($item) |
746
|
|
|
{ |
747
|
|
|
return GetClassTypes::from($item); |
748
|
|
|
} |
749
|
|
|
|
750
|
|
|
/** |
751
|
|
|
* return a practical list of data types for any value or variable |
752
|
|
|
* |
753
|
|
|
* @param mixed $item |
754
|
|
|
* the item to examine |
755
|
|
|
* @return string[] |
756
|
|
|
* the list of type(s) that this item can be |
757
|
|
|
*/ |
758
|
|
|
function get_duck_types($item) |
759
|
|
|
{ |
760
|
|
|
return \GanbaroDigital\MissingBits\TypeInspectors\GetDuckTypes::from($item); |
761
|
|
|
} |
762
|
|
|
|
763
|
|
|
/** |
764
|
|
|
* what namespace does a class live within? |
765
|
|
|
* |
766
|
|
|
* @param string|object $item |
767
|
|
|
* the item to examine |
768
|
|
|
* @return string |
769
|
|
|
* the class's namespace |
770
|
|
|
* @throws InvalidArgumentException |
771
|
|
|
* - if we have not been given a string or object |
772
|
|
|
* - if the string does not contain the name of a defined |
773
|
|
|
* class / interface / trait |
774
|
|
|
*/ |
775
|
|
|
function get_namespace($item) |
776
|
|
|
{ |
777
|
|
|
return GetNamespace::from($item); |
778
|
|
|
} |
779
|
|
|
|
780
|
|
|
/** |
781
|
|
|
* do we have a numeric type? if so, what is it? |
782
|
|
|
* |
783
|
|
|
* @param mixed $item |
784
|
|
|
* the item to examine |
785
|
|
|
* @return string|null |
786
|
|
|
* the numeric type, or null if it is not numeric |
787
|
|
|
*/ |
788
|
|
|
function get_numeric_type($item) |
789
|
|
|
{ |
790
|
|
|
return GetNumericType::from($item); |
791
|
|
|
} |
792
|
|
|
|
793
|
|
|
/** |
794
|
|
|
* get the list of extra types that are valid for this specific object |
795
|
|
|
* |
796
|
|
|
* @param object $item |
797
|
|
|
* the object to examine |
798
|
|
|
* @return string[] |
799
|
|
|
* a (possibly empty) list of types for this object |
800
|
|
|
*/ |
801
|
|
|
function get_object_types($item) |
802
|
|
|
{ |
803
|
|
|
return GetObjectTypes::from($item); |
804
|
|
|
} |
805
|
|
|
|
806
|
|
|
/** |
807
|
|
|
* what PHP type is $item? |
808
|
|
|
* |
809
|
|
|
* @param mixed $item |
810
|
|
|
* the data to examine |
811
|
|
|
* @param int $flags |
812
|
|
|
* options to change what we put in the return value |
813
|
|
|
* @return string |
814
|
|
|
* the data type of $item |
815
|
|
|
*/ |
816
|
|
|
function get_printable_type($item, $flags = GetPrintableType::FLAG_DEFAULTS) |
817
|
|
|
{ |
818
|
|
|
return GetPrintableType::of($item, $flags); |
819
|
|
|
} |
820
|
|
|
|
821
|
|
|
/** |
822
|
|
|
* return any data type's type name list |
823
|
|
|
* |
824
|
|
|
* @param mixed $item |
825
|
|
|
* the item to examine |
826
|
|
|
* @return array |
827
|
|
|
* the list of type(s) that this item can be |
828
|
|
|
*/ |
829
|
|
|
function get_strict_types($item) |
830
|
|
|
{ |
831
|
|
|
return GetStrictTypes::from($item); |
832
|
|
|
} |
833
|
|
|
|
834
|
|
|
/** |
835
|
|
|
* get a full list of types that a string might satisfy |
836
|
|
|
* |
837
|
|
|
* @param string $item |
838
|
|
|
* the item to examine |
839
|
|
|
* @return string[] |
840
|
|
|
* the list of type(s) that this item can be |
841
|
|
|
*/ |
842
|
|
|
function get_string_duck_types($item) |
843
|
|
|
{ |
844
|
|
|
return GetStringDuckTypes::from($item); |
845
|
|
|
} |
846
|
|
|
|
847
|
|
|
/** |
848
|
|
|
* get a full list of types that a string might satisfy |
849
|
|
|
* |
850
|
|
|
* @param string $item |
851
|
|
|
* the item to examine |
852
|
|
|
* @return string[] |
853
|
|
|
* the list of type(s) that this item can be |
854
|
|
|
*/ |
855
|
|
|
function get_string_types($item) |
856
|
|
|
{ |
857
|
|
|
return GetStringTypes::from($item); |
858
|
|
|
} |
859
|
|
|
|
860
|
|
|
/** |
861
|
|
|
* get the name of a class, minus its namespace |
862
|
|
|
* |
863
|
|
|
* @param string|object $item |
864
|
|
|
* the item to examine |
865
|
|
|
* @return string |
866
|
|
|
* the class's non-qualified classname |
867
|
|
|
* @throws InvalidArgumentException |
868
|
|
|
* - if we have not been given a string or object |
869
|
|
|
* - if the string does not contain the name of a defined |
870
|
|
|
* class / interface / trait |
871
|
|
|
*/ |
872
|
|
|
function strip_namespace($item) |
873
|
|
|
{ |
874
|
|
|
return StripNamespace::from($item); |
875
|
|
|
} |
876
|
|
|
|