1 | <?php |
||
17 | class Utils |
||
18 | { |
||
19 | private static $jsonErrors = [ |
||
20 | JSON_ERROR_NONE => 'No errors', |
||
21 | JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', |
||
22 | JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch', |
||
23 | JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', |
||
24 | JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', |
||
25 | JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded', |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * Returns whether two variables are equal. Always compares |
||
30 | * values, not references, and walks each variable recursively |
||
31 | * if needed. |
||
32 | * |
||
33 | * @param mixed $a |
||
34 | * @param mixed $b |
||
35 | * |
||
36 | * @return bool |
||
37 | */ |
||
38 | 50 | public static function areEqual($a, $b) |
|
42 | |||
43 | /** |
||
44 | * Returns whether a regex is valid. Regex is supposed to be |
||
45 | * non-anchored (see JSON Schema Validation 3.3). |
||
46 | * |
||
47 | * @param string $regex |
||
48 | * |
||
49 | * @return bool |
||
50 | */ |
||
51 | 56 | public static function isValidRegex($regex) |
|
57 | |||
58 | /** |
||
59 | * Returns whether a string matches a regex. Regex is supposed to be |
||
60 | * non-anchored (see JSON Schema Validation 3.3). |
||
61 | * |
||
62 | * @param string $string |
||
63 | * @param string $regex |
||
64 | * |
||
65 | * @return bool |
||
66 | */ |
||
67 | 44 | public static function matchesRegex($string, $regex) |
|
73 | |||
74 | /** |
||
75 | * Returns the JSON-decoded content of a file. |
||
76 | * |
||
77 | * @param $filePath |
||
78 | * |
||
79 | * @return mixed |
||
80 | * |
||
81 | * @throws \RuntimeException |
||
82 | * @throws JsonDecodeException |
||
83 | */ |
||
84 | 95 | public static function loadJsonFromFile($filePath) |
|
102 | |||
103 | /** |
||
104 | * @codeCoverageIgnore (depends on PHP version) |
||
105 | * |
||
106 | * Returns the error message resulting from the last call to |
||
107 | * json_encode or json_decode functions. |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | public static function lastJsonErrorMessage() |
||
125 | |||
126 | 50 | private static function doAreEqual($a, $b, array $stack) |
|
154 | |||
155 | 23 | private static function areArrayEqual($a, $b, array $stack) |
|
173 | } |
||
174 |