-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathValueValidator.php
57 lines (49 loc) · 1.36 KB
/
ValueValidator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* ArangoDB PHP client: value validator
*
* @package ArangoDBClient
* @author Jan Steemann
* @copyright Copyright 2012, triagens GmbH, Cologne, Germany
*/
namespace ArangoDBClient;
/**
* A simple validator for values to be stored in the database
*
* @package ArangoDBClient
* @since 0.2
*/
class ValueValidator
{
/**
* Validate the value of a variable
*
* Allowed value types are string, integer, double and boolean. Arrays are also allowed if they contain only one of the former types.
*
* @throws ClientException
*
* @param mixed $value - value to validate
*
* @return void - will throw if an invalid value type is passed
*/
public static function validate($value)
{
if (is_string($value) || is_int($value) || is_float($value) || is_bool($value) || null === $value) {
// type is allowed
return;
}
if (is_array($value)) {
// must check all elements contained
foreach ($value as $subValue) {
self::validate($subValue);
}
return;
}
if ($value instanceof Collection) {
return;
}
// type is invalid
throw new ClientException('Invalid bind parameter value');
}
}
class_alias(ValueValidator::class, '\triagens\ArangoDb\ValueValidator');