From cb631785da718e0e1abb9f764b4f500a2d485888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Sun, 25 Apr 2021 11:58:29 +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 | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/System/Di/Container.php b/System/Di/Container.php index 3083dab6..af6125de 100644 --- a/System/Di/Container.php +++ b/System/Di/Container.php @@ -131,7 +131,7 @@ class Container extends BaseObject private function resolve($class, $constrict, $config): object { /** @var ReflectionClass $reflect */ - [$reflect, $dependencies] = $this->resolveDependencies($class, $constrict); + [$reflect, $dependencies] = $this->resolveDependencies($class); if (empty($reflect)) { throw new NotFindClassException($class); } @@ -210,31 +210,29 @@ class Container extends BaseObject /** * @param $class - * @param array $constrict * @return array|null * @throws ReflectionException|NotFindClassException */ - private function resolveDependencies($class, $constrict = []): ?array + private function resolveDependencies($class): ?array { - if (!isset($this->_reflection[$class])) { - if (!class_exists($class)) { - return null; - } - $reflection = new ReflectionClass($class); - if (!$reflection->isInstantiable()) { - return null; - } - $this->_reflection[$class] = $reflection; - } else { - $reflection = $this->_reflection[$class]; + if (isset($this->_reflection[$class])) { + return [$this->_reflection[$class], $this->_constructs[$class]]; } - if (!is_null($construct = $reflection->getConstructor())) { - $constrict = $this->resolveMethodParam($construct); + + $reflection = new ReflectionClass($class); + if (!$reflection->isInstantiable()) { + return null; } $this->scanProperty($reflection); - return [$reflection, $constrict]; + $this->_reflection[$class] = $reflection; + + if (!is_null($construct = $reflection->getConstructor())) { + $this->_constructs[$class] = $this->resolveMethodParam($construct); + } + + return [$reflection, $this->_constructs[$class]]; }