-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathConfig.php
64 lines (54 loc) · 1.34 KB
/
Config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
/**
* This file is part of Simps.
*
* @link https://simps.io
* @document https://doc.simps.io
* @license https://github.com/simple-swoole/simps/blob/master/LICENSE
*/
namespace Simps\Utils;
class Config
{
private static $instance;
private static $config = [];
private function __construct()
{
}
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
/**
* @param $keys
* @param null $default
* @return null|mixed
*/
public function get($keys, $default = null)
{
$keys = explode('.', strtolower($keys));
if (empty($keys)) {
return $default;
}
$file = array_shift($keys);
if (empty(self::$config[$file])) {
if (! is_file(CONFIG_PATH . $file . '.php')) {
return $default;
}
self::$config[$file] = include CONFIG_PATH . $file . '.php';
}
$config = self::$config[$file];
while ($keys) {
$key = array_shift($keys);
if (! isset($config[$key])) {
$config = $default;
break;
}
$config = $config[$key];
}
return $config;
}
}