1 | <?php |
||
18 | abstract class Util |
||
19 | { |
||
20 | // Check JSON format |
||
21 | 2 | public static function isJson (string $string) : bool |
|
22 | { |
||
23 | 2 | if (is_numeric($string) || $string === 'true' || $string === 'false' || $string === 'null' || empty($string)) : |
|
24 | 1 | return false; |
|
25 | endif; |
||
26 | |||
27 | // try to decode string |
||
28 | 1 | json_decode($string); |
|
29 | |||
30 | // check if error occured |
||
31 | 1 | return json_last_error() === JSON_ERROR_NONE; |
|
32 | } |
||
33 | |||
34 | 2 | public static function prepareJson (string $input) |
|
35 | { |
||
36 | 2 | if (!Util::isJson($input)) : |
|
37 | 1 | throw new CondorcetException(15); |
|
38 | endif; |
||
39 | |||
40 | 1 | return json_decode($input, true); |
|
41 | } |
||
42 | |||
43 | // Generic action before parsing data from string input |
||
44 | 70 | public static function prepareParse (string $input, bool $allowFile) : array |
|
69 | |||
70 | // Simplify Condorcet Var_Dump. Transform object to String. |
||
71 | 50 | public static function format ($input, bool $convertObject = true) |
|
103 | } |
||
104 |