1 | <?php |
||
5 | class Data |
||
6 | { |
||
7 | |||
8 | private $config; |
||
9 | private $context = 'default'; |
||
10 | |||
11 | 4 | public function __construct($path = null, $namespace = null) |
|
12 | { |
||
13 | 4 | if(is_dir($path)) { |
|
14 | 3 | $dir = new Directory($path); |
|
15 | 3 | $this->config = ['default' => $this->expand($dir->parse(), $namespace)]; |
|
16 | 3 | foreach ($dir->getContexts() as $context) { |
|
17 | 2 | $this->config[$context] = array_merge( |
|
18 | 2 | $this->config['default'], $this->expand($dir->parse($context), $namespace) |
|
19 | 2 | ); |
|
20 | 3 | } |
|
21 | 4 | } else if(is_file($path)) { |
|
22 | 2 | $this->config[$this->context] = $this->expand(File::read($path), $namespace); |
|
23 | 1 | } |
|
24 | 4 | } |
|
25 | |||
26 | 4 | public function isKeySet($key) |
|
30 | |||
31 | 4 | public function get($key) |
|
35 | |||
36 | 1 | public function setContext($context) |
|
40 | |||
41 | 1 | public function set($key, $value) |
|
50 | |||
51 | 1 | private function setValue($keys, $value, $config) |
|
61 | |||
62 | 4 | private function expand($array, $namespace, $prefix = null) |
|
77 | } |
||
78 |