1 | <?php |
||
8 | class Config implements ArrayAccess |
||
9 | { |
||
10 | private $converter; |
||
11 | |||
12 | public function __construct(Framework $framework, Filesystem $fs, Converter $converter) |
||
13 | { |
||
14 | $this->converter = $converter; |
||
15 | |||
16 | $filename = $fs->getPath("config.php"); |
||
17 | if (!file_exists($filename)) { |
||
18 | $filename = $framework->getPath('resources/default/config.php'); |
||
19 | } |
||
20 | $data = include $filename; |
||
21 | foreach ($data as $k => $v) { |
||
22 | if ($v instanceof Closure) { |
||
23 | $v = $v(); |
||
24 | } |
||
25 | $this->$k = $v; |
||
26 | if (is_array($v) || is_object($v)) { |
||
27 | $this->$k = $converter->toObject($v); |
||
28 | } |
||
29 | } |
||
30 | } |
||
31 | |||
32 | 1 | public function offsetExists($offset) |
|
36 | |||
37 | 31 | public function offsetGet($offset) |
|
46 | |||
47 | 1 | public function offsetSet($offset, $value) |
|
58 | |||
59 | 1 | public function offsetUnset($offset) |
|
66 | |||
67 | public function require(string $offset) |
||
73 | |||
74 | 31 | private function getNode(string $offset, bool $createIfNone = false) |
|
95 | } |
||
96 |