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