Total Complexity | 10 |
Total Lines | 49 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
3 | class Config |
||
4 | { |
||
5 | private $params = []; |
||
6 | |||
7 | function __construct(array $arguments, array $defaults = []) |
||
8 | { |
||
9 | $this->set('path', ROOT_DIR); |
||
10 | |||
11 | $self = $this; |
||
12 | array_walk($defaults, function($setting, $key) use ($self) { |
||
13 | $self->set($key, $setting); |
||
14 | }); |
||
15 | |||
16 | foreach($arguments as $key => $value) { |
||
17 | $this->set($key, $value); |
||
18 | } |
||
19 | } |
||
20 | |||
21 | public function set(string $key, $param): void |
||
22 | { |
||
23 | $this->params[$key] = $param; |
||
24 | } |
||
25 | |||
26 | public function get(string $key) |
||
27 | { |
||
28 | $result = @$this->params[$key] ?: null; |
||
29 | $config = $this; |
||
30 | |||
31 | return !is_string($result) ? $result : preg_replace_callback('/(\$\{([\w\.-_]+)\})/', function($matches) use ($config) { |
||
32 | return $config->get($matches[2]); |
||
33 | }, $result); |
||
34 | } |
||
35 | |||
36 | public function getOr(string ...$keys) |
||
47 | } |
||
48 | |||
49 | public function getAll(): array |
||
52 | } |
||
53 | } |
||
54 |