From 764a7f4eb78759311a5a653001c50f7725e88e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Tue, 25 Apr 2023 11:51:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Container.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Container.php b/Container.php index 1f538c4..32c9ee3 100644 --- a/Container.php +++ b/Container.php @@ -132,19 +132,16 @@ class Container implements ContainerInterface /** * @param string $className - * @return ReflectionClass|null + * @return ReflectionClass * @throws ReflectionException */ - public function getReflectionClass(string $className): ?ReflectionClass + public function getReflectionClass(string $className): ReflectionClass { if (isset($this->_reflection[$className])) { return $this->_reflection[$className]; } $class = new ReflectionClass($className); - if (!$class->isInstantiable()) { - return null; - } return $this->_reflection[$className] = $class; } @@ -159,8 +156,9 @@ class Container implements ContainerInterface */ public function make(string $className, array $construct = [], array $config = []): ?object { - if (($reflect = $this->getReflectionClass($className)) === null) { - return null; + $reflect = $this->getReflectionClass($className); + if (!$reflect->isInstantiable()) { + throw new ReflectionException('Class ' . $className . ' cannot be instantiated'); } $constructorHandler = $reflect->getConstructor();