1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | namespace OpenSearch\Common\Exceptions\Serializer; |
23: | |
24: | use OpenSearch\Common\Exceptions\OpenSearchException; |
25: | |
26: | |
27: | |
28: | |
29: | class JsonErrorException extends \Exception implements OpenSearchException |
30: | { |
31: | |
32: | |
33: | |
34: | private $input; |
35: | |
36: | |
37: | |
38: | |
39: | private $result; |
40: | |
41: | |
42: | |
43: | |
44: | private static $messages = array( |
45: | JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded', |
46: | JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON', |
47: | JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded', |
48: | JSON_ERROR_SYNTAX => 'Syntax error', |
49: | JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded', |
50: | JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded', |
51: | JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded', |
52: | JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given', |
53: | |
54: | |
55: | 9 => 'Decoding of value would result in invalid PHP property name', |
56: | 10 => 'Attempted to decode nonexistent UTF-16 code-point' |
57: | ); |
58: | |
59: | |
60: | |
61: | |
62: | |
63: | public function __construct(int $code, $input, $result, ?\Throwable $previous = null) |
64: | { |
65: | if (isset(self::$messages[$code]) !== true) { |
66: | throw new \InvalidArgumentException(sprintf('Encountered unknown JSON error code: [%d]', $code)); |
67: | } |
68: | |
69: | parent::__construct(self::$messages[$code], $code, $previous); |
70: | $this->input = $input; |
71: | $this->result = $result; |
72: | } |
73: | |
74: | |
75: | |
76: | |
77: | public function getInput() |
78: | { |
79: | return $this->input; |
80: | } |
81: | |
82: | |
83: | |
84: | |
85: | public function getResult() |
86: | { |
87: | return $this->result; |
88: | } |
89: | } |
90: | |