This commit is contained in:
2023-04-25 11:51:26 +08:00
parent 7b5b21b305
commit 764a7f4eb7
+5 -7
View File
@@ -132,19 +132,16 @@ class Container implements ContainerInterface
/** /**
* @param string $className * @param string $className
* @return ReflectionClass|null * @return ReflectionClass
* @throws ReflectionException * @throws ReflectionException
*/ */
public function getReflectionClass(string $className): ?ReflectionClass public function getReflectionClass(string $className): ReflectionClass
{ {
if (isset($this->_reflection[$className])) { if (isset($this->_reflection[$className])) {
return $this->_reflection[$className]; return $this->_reflection[$className];
} }
$class = new ReflectionClass($className); $class = new ReflectionClass($className);
if (!$class->isInstantiable()) {
return null;
}
return $this->_reflection[$className] = $class; return $this->_reflection[$className] = $class;
} }
@@ -159,8 +156,9 @@ class Container implements ContainerInterface
*/ */
public function make(string $className, array $construct = [], array $config = []): ?object public function make(string $className, array $construct = [], array $config = []): ?object
{ {
if (($reflect = $this->getReflectionClass($className)) === null) { $reflect = $this->getReflectionClass($className);
return null; if (!$reflect->isInstantiable()) {
throw new ReflectionException('Class ' . $className . ' cannot be instantiated');
} }
$constructorHandler = $reflect->getConstructor(); $constructorHandler = $reflect->getConstructor();