Conditions | 6 |
Paths | 12 |
Total Lines | 28 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
24 | public function load($resource) |
||
25 | { |
||
26 | // check the extension. If it's not provided we'll add .xml |
||
27 | if (pathinfo($resource, PATHINFO_EXTENSION) === "") { |
||
28 | $resource .= ".xml"; |
||
29 | } |
||
30 | |||
31 | $file = false; |
||
32 | |||
33 | if ($this->locator) { |
||
34 | // pass it to the locator (if set) and than include the file |
||
35 | $file = $this->locator->locate($resource); |
||
36 | } elseif (is_file($resource) && is_readable($resource)) { |
||
37 | // check if the $resource is a real file and include it |
||
38 | $file = $resource; |
||
39 | } |
||
40 | |||
41 | if ($file) { |
||
42 | $xmlstring = file_get_contents($file); |
||
43 | $xml = simplexml_load_string($xmlstring); |
||
44 | $json = json_encode($xml); |
||
45 | $array = json_decode($json, true); |
||
46 | |||
47 | return $array; |
||
48 | } |
||
49 | |||
50 | return null; |
||
51 | } |
||
52 | } |
||
53 |