This commit is contained in:
2023-12-18 21:55:43 +08:00
parent 4a168cb4a0
commit c6e9133566
2 changed files with 28 additions and 5 deletions
+26
View File
@@ -174,6 +174,32 @@ class Container implements ContainerInterface
}
/**
* @param ReflectionClass $reflect
* @param array $construct
* @param array $config
* @return object|null
* @throws ReflectionException
*/
public function makeReflection(ReflectionClass $reflect, array $construct = [], array $config = []): ?object
{
if (isset($this->_singletons[$reflect->getName()])) {
return $this->_singletons[$reflect->getName()];
}
if (!$reflect->isInstantiable()) {
throw new ReflectionException('Class ' . $reflect->getName() . ' cannot be instantiated');
}
if (($handler = $reflect->getConstructor()) !== null) {
$construct = $this->getMethodParams($handler);
}
$newInstance = $reflect->newInstanceArgs($construct);
return $this->runInit($reflect, static::configure($newInstance, $config));
}
/**
* @param ReflectionClass $reflect
* @param object $object