This commit is contained in:
2020-09-17 13:56:57 +08:00
parent 06ba4acd51
commit 6f8e024fae
11 changed files with 77 additions and 64 deletions
+7 -5
View File
@@ -54,9 +54,11 @@ class Config extends Component
*/
public static function get($key, $try = FALSE, $default = null)
{
$explode = explode('.', $key);
$instance = Snowflake::app()->config->getData();
foreach ($explode as $index => $value) {
if (strpos($key, '.') === false) {
return isset($instance[$key]) ? $instance[$key] : $default;
}
foreach (explode('.', $key) as $index => $value) {
if (empty($value)) {
continue;
}
@@ -66,10 +68,10 @@ class Config extends Component
}
return $default;
}
$instance = $instance[$value];
if (!is_array($instance) && $index + 1 < count($explode)) {
throw new ConfigException(sprintf(self::ERROR_MESSAGE, $key));
if (!is_array($instance[$value]) ) {
return $instance[$value];
}
$instance = $instance[$value];
}
return empty($instance) ? $default : $instance;
}