| Total Complexity | 13 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 3 | class Config |
||
| 4 | { |
||
| 5 | private $params = []; |
||
| 6 | |||
| 7 | function __construct(array $argv, 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( |
||
| 14 | $key, |
||
| 15 | $setting |
||
| 16 | ); |
||
| 17 | }); |
||
| 18 | |||
| 19 | foreach($argv as $arg) { |
||
| 20 | $e = explode('=', $arg); |
||
| 21 | if (count($e) === 2) { |
||
| 22 | $this->set($e[0], $e[1]); |
||
| 23 | } else { |
||
| 24 | $this->set($e[0], true); |
||
| 25 | } |
||
| 26 | } |
||
| 27 | |||
| 28 | $this->set('generator', to_camel_case(@$argv[1] ?: '')); |
||
| 29 | $this->set('command', @$argv[2] ?: ''); |
||
| 30 | } |
||
| 31 | |||
| 32 | public function set(string $key, $param): void |
||
| 33 | { |
||
| 34 | $this->params[$key] = $param; |
||
| 35 | } |
||
| 36 | |||
| 37 | public function get(string $key) |
||
| 38 | { |
||
| 39 | $result = @$this->params[$key] ?: null; |
||
| 40 | $config = $this; |
||
| 41 | |||
| 42 | return !is_string($result) ? $result : preg_replace_callback('/(\$\{([\w\.-_]+)\})/', function($matches) use ($config) { |
||
| 43 | return $config->get($matches[2]); |
||
| 44 | }, $result); |
||
| 45 | } |
||
| 46 | |||
| 47 | public function getOr(string ...$keys) |
||
| 60 | } |
||
| 61 | |||
| 62 | public function getAll(): array |
||
| 65 | } |
||
| 66 | } |
||
| 67 |