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