1 | <?php |
||
5 | class Config |
||
6 | { |
||
7 | |||
8 | private $config; |
||
9 | private $context = 'default'; |
||
10 | |||
11 | 11 | public function __construct($path = null, $namespace = null) { |
|
12 | 11 | if (is_dir($path)) { |
|
13 | 7 | $dir = new Directory($path); |
|
14 | 7 | $this->config = ['default' => $this->expand($dir->parse(), $namespace)]; |
|
15 | 7 | foreach ($dir->getContexts() as $context) { |
|
16 | 3 | $this->config[$context] = array_merge( |
|
17 | 7 | $this->config['default'], $this->expand($dir->parse($context), $namespace) |
|
18 | ); |
||
19 | } |
||
20 | 4 | } else if (is_file($path)) { |
|
21 | 2 | $this->config[$this->context] = $this->expand(File::read($path), $namespace); |
|
22 | } |
||
23 | 11 | } |
|
24 | |||
25 | 9 | public static function readPath($path, $namespace = null) { |
|
26 | 9 | return new Config($path, $namespace); |
|
27 | } |
||
28 | |||
29 | public function isKeySet($key) { |
||
32 | |||
33 | 11 | public function get($key, $default = null) { |
|
34 | 11 | return isset($this->config[$this->context][$key]) ? $this->config[$this->context][$key] : $default; |
|
36 | |||
37 | 2 | public function setContext($context) { |
|
40 | |||
41 | 5 | public function set($key, $value) { |
|
49 | |||
50 | 5 | private function setValue($keys, $value, $config) { |
|
59 | |||
60 | 10 | private function expand($array, $namespace, $prefix = null) { |
|
75 | |||
76 | } |
||
77 |