1 | <?php namespace CMPayments\Json; |
||
18 | class Json |
||
19 | { |
||
20 | const SCHEMA = 'Schema'; |
||
21 | const INPUT = 'Input'; |
||
22 | const ERRORS = 'errors'; |
||
23 | const WARNINGS = 'warnings'; |
||
24 | |||
25 | /** |
||
26 | * @var null|object|string |
||
27 | */ |
||
28 | private $input = null; |
||
29 | |||
30 | /** |
||
31 | * @var null|object|string |
||
32 | */ |
||
33 | private $schema = null; |
||
34 | |||
35 | /** |
||
36 | * @var bool |
||
37 | */ |
||
38 | private $isValid = false; |
||
39 | |||
40 | /** |
||
41 | * @var null|string |
||
42 | */ |
||
43 | private $encodedJSON; |
||
44 | |||
45 | /** |
||
46 | * @var bool |
||
47 | */ |
||
48 | private $validatedInput = null; |
||
49 | |||
50 | /** |
||
51 | * Json constructor. |
||
52 | * |
||
53 | * @param string $input |
||
54 | */ |
||
55 | public function __construct($input) |
||
59 | |||
60 | /** |
||
61 | * Validates $this->input and optionally against $this->schema as well |
||
62 | * |
||
63 | * @param null|string $schema |
||
64 | * @param array $passthru Stores the error(s) that might occur during validation |
||
65 | * @param array $options |
||
66 | * |
||
67 | * @return bool |
||
68 | * @throws JsonException|ParseException|JsonLintException|ValidateSchemaException|bool |
||
69 | */ |
||
70 | public function validate($schema = null, &$passthru = [], $options = []) |
||
125 | |||
126 | /** |
||
127 | * Returns the encoded JSON |
||
128 | * |
||
129 | * @return string |
||
130 | */ |
||
131 | public function getEncodedJSON() |
||
140 | |||
141 | /** |
||
142 | * Returns the decoded JSON |
||
143 | * |
||
144 | * @return mixed|null|string |
||
145 | * @throws JsonException |
||
146 | */ |
||
147 | public function getDecodedJSON() |
||
157 | |||
158 | /** |
||
159 | * Validates if a string is valid JSON and converts it back to an object |
||
160 | * |
||
161 | * @param string|null|object $data |
||
162 | * @param string $type |
||
163 | * @param Cache $cache |
||
164 | * |
||
165 | * @return mixed |
||
166 | * @throws JsonException |
||
167 | * @throws ParseException|null |
||
168 | * @throws ValidateSchemaException |
||
169 | */ |
||
170 | private function validateAndConvertData($data, $type, Cache $cache) |
||
211 | |||
212 | /** |
||
213 | * Does the actual decoding of a JSON string |
||
214 | * |
||
215 | * @param $data |
||
216 | * @param $type |
||
217 | * @param bool $assoc |
||
218 | * |
||
219 | * @return mixed |
||
220 | * @throws JsonException |
||
221 | */ |
||
222 | private function decodeJSON($data, $type, $assoc = false) |
||
233 | } |