变更
This commit is contained in:
@@ -12,6 +12,20 @@ namespace Kiri\Abstracts;
|
|||||||
use Kiri\Exception\ConfigException;
|
use Kiri\Exception\ConfigException;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $key
|
||||||
|
* @param $try
|
||||||
|
* @return void
|
||||||
|
* @throws ConfigException
|
||||||
|
*/
|
||||||
|
function ConfigTry($key, $try): void
|
||||||
|
{
|
||||||
|
if ($try) {
|
||||||
|
throw new ConfigException(sprintf(Config::ERROR_MESSAGE, $key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Config
|
* Class Config
|
||||||
* @package Kiri\Base
|
* @package Kiri\Base
|
||||||
@@ -58,7 +72,7 @@ class Config extends Component
|
|||||||
/**
|
/**
|
||||||
* @param $key
|
* @param $key
|
||||||
* @param bool $try
|
* @param bool $try
|
||||||
* @param mixed|null $default
|
* @param mixed $default
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
@@ -69,15 +83,17 @@ class Config extends Component
|
|||||||
}
|
}
|
||||||
$array = explode('.', $key);
|
$array = explode('.', $key);
|
||||||
$data = static::$data[array_shift($array)] ?? null;
|
$data = static::$data[array_shift($array)] ?? null;
|
||||||
if (($data == null || !is_array($data)) && count($array) > 0) {
|
if ($data === null) {
|
||||||
|
return $default;
|
||||||
|
} else if (count($array) === 0) {
|
||||||
|
return $data;
|
||||||
|
} else if (!is_array($data)) {
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
foreach ($array as $value) {
|
foreach ($array as $value) {
|
||||||
$data = $data[$value] ?? null;
|
$data = $data[$value] ?? null;
|
||||||
if ($data === null) {
|
if ($data === null) {
|
||||||
if ($try) {
|
ConfigTry($key, $try);
|
||||||
throw new ConfigException(sprintf(self::ERROR_MESSAGE, $key));
|
|
||||||
}
|
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user