forked from SugiPHP/Config
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXmlLoader.php
More file actions
48 lines (39 loc) · 1.05 KB
/
XmlLoader.php
File metadata and controls
48 lines (39 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* @package SugiPHP
* @subpackage Config
* @author Plamen Popov <tzappa@gmail.com>
* @license http://opensource.org/licenses/mit-license.php (MIT License)
*/
namespace SugiPHP\Config;
class XmlLoader implements LoaderInterface
{
protected $locator;
public function __construct(LocatorInterface $locator = null)
{
$this->locator = $locator;
}
public function load($resource)
{
// check the extension. If it's not provided we'll add .xml
if (pathinfo($resource, PATHINFO_EXTENSION) === "") {
$resource .= ".xml";
}
$file = false;
if ($this->locator) {
// pass it to the locator (if set) and than include the file
$file = $this->locator->locate($resource);
} elseif (is_file($resource) && is_readable($resource)) {
// check if the $resource is a real file and include it
$file = $resource;
}
if ($file) {
$xmlstring = file_get_contents($file);
$xml = simplexml_load_string($xmlstring);
$json = json_encode($xml);
$array = json_decode($json, true);
return $array;
}
return null;
}
}