| 1 | <?php |
||
| 5 | class Config |
||
| 6 | { |
||
| 7 | private static $baseDir = __DIR__."/../config/"; |
||
| 8 | private static $store = []; |
||
| 9 | |||
| 10 | 27 | public static function load($path) |
|
| 11 | { |
||
| 12 | 27 | if (!self::loaded($path)) { |
|
| 13 | 3 | self::loadToStore($path); |
|
| 14 | } |
||
| 15 | |||
| 16 | 27 | return self::loadFromStore($path); |
|
| 17 | } |
||
| 18 | |||
| 19 | 24 | public static function set($key, $val) |
|
| 23 | |||
| 24 | 3 | private static function loadToStore($path) |
|
| 30 | |||
| 31 | 27 | private static function loadFromStore($path) |
|
| 32 | { |
||
| 33 | 27 | $vars = explode(".", $path); |
|
| 34 | 27 | $file = array_shift($vars); |
|
| 35 | 27 | $config = self::$store[$file]; |
|
| 36 | |||
| 37 | 27 | foreach ($vars as $var) { |
|
| 38 | 24 | if (!is_array($config)) { |
|
| 39 | return null; |
||
| 40 | } |
||
| 41 | 24 | if (!array_key_exists($var, $config)) { |
|
| 42 | return null; |
||
| 43 | } |
||
| 44 | 24 | $config = $config[$var]; |
|
| 45 | } |
||
| 46 | 27 | return $config; |
|
| 47 | } |
||
| 48 | |||
| 49 | 27 | private static function loaded($path) |
|
| 55 | } |
||
| 56 |