1 | <?php |
||
19 | class Php implements ParserInterface |
||
20 | { |
||
21 | /** |
||
22 | * {@inheritDoc} |
||
23 | * Loads a PHP file and gets its' contents as an array |
||
24 | * |
||
25 | * @throws ParseException If the PHP file throws an exception |
||
26 | * @throws UnsupportedFormatException If the PHP file does not return an array |
||
27 | */ |
||
28 | 12 | public function parseFile($filename) |
|
45 | |||
46 | /** |
||
47 | * {@inheritDoc} |
||
48 | 9 | * Loads a PHP string and gets its' contents as an array |
|
49 | 3 | * |
|
50 | 1 | * @throws ParseException If the PHP string throws an exception |
|
51 | * @throws UnsupportedFormatException If the PHP string does not return an array |
||
52 | */ |
||
53 | 9 | public function parseString($config) |
|
54 | 3 | { |
|
55 | // Handle PHP start tag |
||
56 | $config = trim($config); |
||
57 | 6 | if (substr($config, 0, 2) === '<?') { |
|
58 | $config = '?>' . $config; |
||
59 | } |
||
60 | |||
61 | // Eval the string, if it throws an exception, rethrow it |
||
62 | try { |
||
63 | 3 | $data = $this->isolate($config); |
|
64 | } catch (Exception $exception) { |
||
65 | 3 | throw new ParseException( |
|
66 | [ |
||
67 | 'message' => 'PHP string threw an exception', |
||
68 | 'exception' => $exception, |
||
69 | ] |
||
70 | ); |
||
71 | } |
||
72 | |||
73 | // Complete parsing |
||
74 | return $this->parse($data); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Completes parsing of PHP data |
||
79 | * |
||
80 | * @param array $data |
||
81 | * @param strring $filename |
||
82 | * |
||
83 | * @throws ParseException If there is an error parsing the PHP data |
||
84 | */ |
||
85 | protected function parse($data = null, $filename = null) |
||
86 | { |
||
87 | // If we have a callable, run it and expect an array back |
||
88 | if (is_callable($data)) { |
||
89 | $data = call_user_func($data); |
||
90 | } |
||
91 | |||
92 | // Check for array, if its anything else, throw an exception |
||
93 | if (!is_array($data)) { |
||
94 | throw new UnsupportedFormatException('PHP data does not return an array'); |
||
95 | } |
||
96 | |||
97 | return $data; |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Runs PHP string in isolated method |
||
102 | * |
||
103 | * @param string $EGsfKPdue7ahnMTy |
||
104 | * |
||
105 | * @return array |
||
106 | */ |
||
107 | protected function isolate($EGsfKPdue7ahnMTy) |
||
111 | |||
112 | /** |
||
113 | * {@inheritDoc} |
||
114 | */ |
||
115 | public static function getSupportedExtensions() |
||
119 | } |
||
120 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: