1 | <?php |
||
8 | class Config implements ArrayAccess |
||
9 | { |
||
10 | protected $app; |
||
11 | protected $converter; |
||
12 | |||
13 | public function __construct(Application $app, Framework $framework, Filesystem $fs, Converter $converter) |
||
14 | { |
||
15 | $this->app = $app; |
||
16 | $this->converter = $converter; |
||
17 | |||
18 | $filename = $fs->getPath("config.php"); |
||
19 | if (!file_exists($filename)) { |
||
20 | $filename = $framework->getPath('resources/default/config.php'); |
||
21 | } |
||
22 | $data = include $filename; |
||
23 | foreach ($data as $k => $v) { |
||
24 | $this->$k = $v; |
||
25 | if ($v instanceof Closure) { |
||
26 | continue; |
||
27 | } |
||
28 | if (is_array($v) || is_object($v)) { |
||
29 | $this->$k = $converter->toObject($v); |
||
30 | } |
||
31 | } |
||
32 | } |
||
33 | |||
34 | 1 | public function offsetExists($offset) |
|
38 | |||
39 | 45 | public function offsetGet($offset) |
|
48 | |||
49 | 1 | public function offsetSet($offset, $value) |
|
60 | |||
61 | 1 | public function offsetUnset($offset) |
|
68 | |||
69 | public function require(string $offset) |
||
75 | |||
76 | 45 | private function getNode(string $offset, bool $createIfNone = false) |
|
107 | } |
||
108 |