From ebf8faa90357c976fb6b1f61ddff9b4e48a390a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Sun, 25 Apr 2021 15:45:40 +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/Container.php | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/System/Di/Container.php b/System/Di/Container.php index 9b04b214..c6223688 100644 --- a/System/Di/Container.php +++ b/System/Di/Container.php @@ -71,7 +71,7 @@ class Container extends BaseObject public function get($class, $constrict = [], $config = []): mixed { if (isset($this->_singletons[$class])) { - return clone $this->_singletons[$class]; + return $this->_singletons[$class]; } else if (!isset($this->_constructs[$class])) { return $this->resolve($class, $constrict, $config); } @@ -230,26 +230,17 @@ class Container extends BaseObject */ private function resolveDependencies($class): ?array { - if (!isset($this->_constructs[$class])) { - $this->_constructs[$class] = ['class' => $class]; + if (!isset($this->_reflection[$class])) { + $this->_reflection[$class] = new ReflectionClass($class); + if (!$this->_reflection[$class]->isInstantiable()) { + return null; + } + $this->scanProperty($this->_reflection[$class]); } - if (isset($this->_reflection[$class])) { - return [$this->_reflection[$class], $this->_constructs[$class] ?? []]; + if (!is_null($constructs = $this->_reflection[$class]->getConstructor())) { + $constructs = $this->resolveMethodParam($constructs); } - - $reflection = new ReflectionClass($class); - if (!$reflection->isInstantiable()) { - return null; - } - $this->scanProperty($reflection); - - $this->_reflection[$class] = $reflection; - if (!is_null($construct = $reflection->getConstructor())) { - $this->_constructs[$class] = array_merge($this->_constructs[$class], - $this->resolveMethodParam($construct) - ); - } - return [$reflection, $this->_constructs[$class] ?? []]; + return [$this->_reflection[$class], $constructs]; }