From cef63a50fc53b8e49a20721975bab8cb2e796c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 3 Sep 2020 15:26:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system/Abstracts/Config.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/system/Abstracts/Config.php b/system/Abstracts/Config.php index 20ebd329..c8d52f1f 100644 --- a/system/Abstracts/Config.php +++ b/system/Abstracts/Config.php @@ -20,7 +20,7 @@ use Snowflake\Abstracts\Component; class Config extends Component { - const ERROR_MESSAGE = 'The not find :key in app configs.'; + const ERROR_MESSAGE = 'The not find %s in app configs.'; public $data; @@ -43,21 +43,20 @@ class Config extends Component public static function get($key, $try = FALSE, $default = null) { $explode = explode('.', $key); - $instance = Snowflake::app()->getConfig()->getData(); foreach ($explode as $index => $value) { + if (empty($value)) { + continue; + } if (!isset($instance[$value]) && $try) { - throw new ConfigException(str_replace(':key', $key, self::ERROR_MESSAGE)); + throw new ConfigException(sprintf(self::ERROR_MESSAGE, $value)); } $instance = $instance[$value]; if (!is_array($instance) && $index + 1 < count($explode)) { - throw new ConfigException(str_replace(':key', $key, self::ERROR_MESSAGE)); + throw new ConfigException(sprintf(self::ERROR_MESSAGE, $value)); } } - if (empty($instance)) { - return $default; - } - return $instance; + return empty($instance) ? $default : $instance; } /**