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