| 1 | <?php |
||
| 16 | class Json implements FileParserInterface |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * {@inheritDoc} |
||
| 20 | * Loads a JSON file as an array |
||
| 21 | * |
||
| 22 | * @throws ParseException If there is an error parsing the JSON file |
||
| 23 | */ |
||
| 24 | 6 | public function parse($path) |
|
| 25 | { |
||
| 26 | 6 | $data = json_decode(file_get_contents($path), true); |
|
| 27 | |||
| 28 | 6 | if (json_last_error() !== JSON_ERROR_NONE) { |
|
| 29 | 3 | $error_message = 'Syntax error'; |
|
| 30 | 3 | if (function_exists('json_last_error_msg')) { |
|
| 31 | 3 | $error_message = json_last_error_msg(); |
|
| 32 | 2 | } |
|
| 33 | |||
| 34 | $error = array( |
||
| 35 | 3 | 'message' => $error_message, |
|
| 36 | 3 | 'type' => json_last_error(), |
|
| 37 | 3 | 'file' => $path, |
|
| 38 | 2 | ); |
|
| 39 | 3 | throw new ParseException($error); |
|
| 40 | } |
||
| 41 | |||
| 42 | 3 | return $data; |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritDoc} |
||
| 47 | */ |
||
| 48 | 3 | public static function getSupportedExtensions() |
|
| 52 | } |
||
| 53 |