From c2cd9e443969294ad53b7f6e0a6f13b0c7f5678f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 27 Apr 2021 17:14:19 +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/Di/Service.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/System/Di/Service.php b/System/Di/Service.php index e67115a4..b4fe0a15 100644 --- a/System/Di/Service.php +++ b/System/Di/Service.php @@ -45,19 +45,25 @@ class Service extends Component if (isset($this->_components[$id])) { return $this->_components[$id]; } - if (isset($this->_definition[$id])) { - $config = $this->_definition[$id]; - if (!is_object($config)) { - $config = Snowflake::createObject($config); + if (!isset($this->_definition[$id]) && !isset($this->_alias[$id])) { + if ($try === false) { + return null; } - return $this->_components[$id] = $config; - } - if ($try !== false) { throw new ComponentException("Unknown component ID: $id"); } - return null; - } + if (isset($this->_definition[$id])) { + $config = $this->_definition[$id]; + if (is_object($config)) { + return $this->_components[$id] = $config; + } + $object = Snowflake::createObject($config); + } else { + $config = $this->_alias[$id]; + $object = Snowflake::createObject($config); + } + return $this->_components[$id] = $object; + } /** * @param string $className