bytic /
hello
| 1 | <?php |
||
| 2 | |||
| 3 | namespace ByTIC\Hello\Utility; |
||
| 4 | |||
| 5 | use Nip\Config\Config; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Class ConfigHelper |
||
| 9 | * @package ByTIC\Hello\Utility |
||
| 10 | */ |
||
| 11 | class ConfigHelper |
||
| 12 | { |
||
| 13 | public const CONFIG_NAMESPACE = 'hello'; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var null|Config |
||
| 17 | */ |
||
| 18 | protected static $config = null; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param string $key |
||
| 22 | * @param null $default |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 23 | * @return mixed|\Nip\Config\Config |
||
| 24 | */ |
||
| 25 | 4 | public static function get(string $key, $default = null) |
|
| 26 | { |
||
| 27 | 4 | $key = sprintf('%s.%s', static::CONFIG_NAMESPACE, $key); |
|
| 28 | 4 | if (static::$config !== null) { |
|
| 29 | 3 | return static::$config->get($key, $default); |
|
| 30 | } |
||
| 31 | 1 | if (!function_exists('app')) { |
|
| 32 | return $default; |
||
| 33 | } |
||
| 34 | 1 | if (!function_exists('config') || !app()->has('config')) { |
|
| 35 | 1 | return $default; |
|
| 36 | } |
||
| 37 | return config($key, $default); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param Config $object |
||
| 42 | */ |
||
| 43 | 4 | public static function setConfig($object) |
|
| 44 | { |
||
| 45 | 4 | static::$config = $object; |
|
| 46 | 4 | } |
|
| 47 | } |
||
| 48 |