This commit is contained in:
2020-08-31 22:54:41 +08:00
parent 2d79bcabec
commit f09c2800ef
+22
View File
@@ -34,6 +34,8 @@ class Config extends Component
public static function get($key, $try = FALSE, $default = null) public static function get($key, $try = FALSE, $default = null)
{ {
$config = Snowflake::get()->config; $config = Snowflake::get()->config;
if (strpos($key, '.') === false) {
if (isset($config->data[$key])) { if (isset($config->data[$key])) {
return $config->data[$key]; return $config->data[$key];
} else if ($default !== null) { } else if ($default !== null) {
@@ -43,6 +45,26 @@ class Config extends Component
} }
return NULL; return NULL;
} }
$keys = explode('.', $key);
$parent = $config->data[array_shift($keys)] ?? null;
if (empty($parent)) {
return $default;
}
if (empty($keys) || !is_array($parent)) {
return $parent;
}
foreach ($keys as $key) {
if (!isset($parent[$key])) {
return $parent;
}
$parent = $parent[$key];
if (empty($keys) || !is_array($parent)) {
return $parent;
}
}
return $parent;
}
/** /**
* @param $key * @param $key