From bec1a70c5b6d7820aeac4fa63c124cd3bc44d4cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 3 Sep 2020 15:33:55 +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 | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/system/Abstracts/Config.php b/system/Abstracts/Config.php index c8d52f1f..f4651614 100644 --- a/system/Abstracts/Config.php +++ b/system/Abstracts/Config.php @@ -22,7 +22,7 @@ class Config extends Component const ERROR_MESSAGE = 'The not find %s in app configs.'; - public $data; + protected $data; /** @@ -33,6 +33,17 @@ class Config extends Component return $this->data; } + + /** + * @param $key + * @param $value + * @return mixed + */ + public function setData($key, $value) + { + return $this->data[$key] = $value; + } + /** * @param $key * @param bool $try @@ -43,17 +54,20 @@ class Config extends Component public static function get($key, $try = FALSE, $default = null) { $explode = explode('.', $key); - $instance = Snowflake::app()->getConfig()->getData(); + $instance = Snowflake::app()->config->getData(); foreach ($explode as $index => $value) { if (empty($value)) { continue; } - if (!isset($instance[$value]) && $try) { - throw new ConfigException(sprintf(self::ERROR_MESSAGE, $value)); + if (!isset($instance[$value])) { + if ($try) { + throw new ConfigException(sprintf(self::ERROR_MESSAGE, $key)); + } + return $default; } $instance = $instance[$value]; if (!is_array($instance) && $index + 1 < count($explode)) { - throw new ConfigException(sprintf(self::ERROR_MESSAGE, $value)); + throw new ConfigException(sprintf(self::ERROR_MESSAGE, $key)); } } return empty($instance) ? $default : $instance; @@ -68,7 +82,7 @@ class Config extends Component public static function set($key, $value) { $config = Snowflake::app()->config; - return $config->data[$key] = $value; + return $config->setData($key, $value); } /**