1 | <?php |
||
19 | class JsonError |
||
|
|||
20 | { |
||
21 | /** |
||
22 | * User-land implementation of `json_last_error_msg()` for PHP < 5.5. |
||
23 | * |
||
24 | * @return string The last JSON error message |
||
25 | */ |
||
26 | 9 | public static function getLastErrorMessage() |
|
30 | |||
31 | /** |
||
32 | * Returns the error message of a JSON error code. |
||
33 | * |
||
34 | * @param int $error The error code |
||
35 | * |
||
36 | * @return string The error message |
||
37 | */ |
||
38 | 9 | public static function getErrorMessage($error) |
|
39 | { |
||
40 | switch ($error) { |
||
41 | 9 | case JSON_ERROR_NONE: |
|
42 | return 'JSON_ERROR_NONE'; |
||
43 | 9 | case JSON_ERROR_DEPTH: |
|
44 | 4 | return 'JSON_ERROR_DEPTH'; |
|
45 | 5 | case JSON_ERROR_STATE_MISMATCH: |
|
46 | return 'JSON_ERROR_STATE_MISMATCH'; |
||
47 | 5 | case JSON_ERROR_CTRL_CHAR: |
|
48 | return 'JSON_ERROR_CTRL_CHAR'; |
||
49 | 5 | case JSON_ERROR_SYNTAX: |
|
50 | return 'JSON_ERROR_SYNTAX'; |
||
51 | 5 | case JSON_ERROR_UTF8: |
|
52 | 5 | return 'JSON_ERROR_UTF8'; |
|
53 | } |
||
54 | |||
55 | if (version_compare(PHP_VERSION, '5.5.0', '>=')) { |
||
56 | switch ($error) { |
||
57 | case JSON_ERROR_RECURSION: |
||
58 | return 'JSON_ERROR_RECURSION'; |
||
59 | case JSON_ERROR_INF_OR_NAN: |
||
60 | return 'JSON_ERROR_INF_OR_NAN'; |
||
61 | case JSON_ERROR_UNSUPPORTED_TYPE: |
||
62 | return 'JSON_ERROR_UNSUPPORTED_TYPE'; |
||
63 | } |
||
64 | } |
||
65 | |||
66 | return 'JSON_ERROR_UNKNOWN'; |
||
67 | } |
||
68 | |||
69 | private function __construct() |
||
72 | } |
||
73 |