| Total Complexity | 8 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class Config |
||
| 6 | { |
||
| 7 | /** @const string */ |
||
| 8 | const DEFAULT_CONFIG_PATH = __DIR__ . '/Config/default.php'; |
||
| 9 | |||
| 10 | /** @var array */ |
||
| 11 | protected static $config = []; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Load default application configs. |
||
| 15 | * |
||
| 16 | * @param string|array $config |
||
| 17 | * @param bool $force |
||
| 18 | * |
||
| 19 | * @return void |
||
| 20 | */ |
||
| 21 | 3 | public static function set($config = null, bool $force = false) |
|
| 22 | { |
||
| 23 | 3 | if ( ! $force && ! empty(self::$config)) { |
|
| 24 | 3 | return; |
|
| 25 | } |
||
| 26 | |||
| 27 | 2 | if (is_array($config)) { |
|
| 28 | 1 | self::$config = $config; |
|
| 29 | } else { |
||
| 30 | 1 | self::$config = require $config ?? self::DEFAULT_CONFIG_PATH; |
|
| 31 | } |
||
| 32 | 2 | } |
|
| 33 | |||
| 34 | /** |
||
| 35 | * Get config. |
||
| 36 | * |
||
| 37 | * @param string|null $key Key to extract. |
||
| 38 | * |
||
| 39 | * @return mixed |
||
| 40 | */ |
||
| 41 | 5 | public static function get(string $key = null) |
|
| 61 | } |
||
| 62 | } |
||
| 63 |