1 | <?php |
||
16 | class Ini implements FileParserInterface |
||
17 | { |
||
18 | |||
19 | |||
20 | /** |
||
21 | * {@inheritDoc} |
||
22 | * Parses an INI file as an array |
||
23 | * |
||
24 | 6 | * @throws ParseException If there is an error parsing the INI file |
|
25 | */ |
||
26 | 6 | public function parse($path) |
|
27 | { |
||
28 | 6 | $data = @parse_ini_file($path, true); |
|
29 | 3 | ||
30 | 3 | if (!$data) { |
|
31 | $error = error_get_last(); |
||
32 | |||
33 | 3 | // parse_ini_file() may return NULL but set no error if the file contains no parsable data |
|
34 | if (!is_array($error)) { |
||
35 | $error["message"] = "No parsable content in file."; |
||
36 | } |
||
37 | |||
38 | // if file contains no parsable data, no error is set, resulting in any previous error |
||
39 | 3 | // persisting in error_get_last(). in php 7 this can be addressed with error_clear_last() |
|
40 | if (function_exists("error_clear_last")) { |
||
41 | 3 | error_clear_last(); |
|
42 | } |
||
43 | |||
44 | throw new ParseException($error); |
||
84 |