变更
This commit is contained in:
@@ -64,26 +64,24 @@ class Config extends Component
|
|||||||
*/
|
*/
|
||||||
public static function get($key, mixed $default = null, bool $try = FALSE): mixed
|
public static function get($key, mixed $default = null, bool $try = FALSE): mixed
|
||||||
{
|
{
|
||||||
$instance = static::$data;
|
|
||||||
if (!str_contains($key, '.')) {
|
if (!str_contains($key, '.')) {
|
||||||
return $instance[$key] ?? $default;
|
return static::$data[$key] ?? $default;
|
||||||
}
|
}
|
||||||
foreach (explode('.', $key) as $value) {
|
$array = explode('.', $key);
|
||||||
if (empty($value)) {
|
$data = static::$data[array_shift($array)] ?? null;
|
||||||
continue;
|
if (($data == null || !is_array($data)) && count($array) > 0) {
|
||||||
|
return $default;
|
||||||
}
|
}
|
||||||
if (!isset($instance[$value])) {
|
foreach ($array as $value) {
|
||||||
|
$data = $data[$value] ?? null;
|
||||||
|
if ($data === null) {
|
||||||
if ($try) {
|
if ($try) {
|
||||||
throw new ConfigException(sprintf(self::ERROR_MESSAGE, $key));
|
throw new ConfigException(sprintf(self::ERROR_MESSAGE, $key));
|
||||||
}
|
}
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
if (!is_array($instance[$value])) {
|
|
||||||
return $instance[$value];
|
|
||||||
}
|
}
|
||||||
$instance = $instance[$value];
|
return $data;
|
||||||
}
|
|
||||||
return empty($instance) ? $default : $instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user