This commit is contained in:
Yuri Kuznetsov
2022-02-17 17:11:10 +02:00
parent e5a0774e3e
commit 41139f52c8

View File

@@ -40,6 +40,7 @@ use ReflectionParameter;
use ReflectionFunction;
use ReflectionNamedType;
use Throwable;
use Closure;
/**
* Creates an instance by a class name. Uses constructor param names and type hinting to detect which
@@ -179,7 +180,10 @@ class InjectableFactory
!$type->isBuiltin()
) {
try {
$dependencyClass = new ReflectionClass($type->getName());
/** @var class-string */
$dependencyClassName = $type->getName();
$dependencyClass = new ReflectionClass($dependencyClassName);
}
catch (Throwable $e) {
$badClassName = $type->getName();
@@ -239,6 +243,10 @@ class InjectableFactory
{
$injectionList = [];
if (!$callback instanceof Closure) {
$callback = Closure::fromCallable($callback);
}
$function = new ReflectionFunction($callback);
foreach ($function->getParameters() as $param) {
@@ -362,7 +370,10 @@ class InjectableFactory
$type instanceof ReflectionNamedType &&
!$type->isBuiltin()
) {
$paramClass = new ReflectionClass($type->getName());
/** @var class-string */
$dependencyClassName = $type->getName();
$paramClass = new ReflectionClass($dependencyClassName);
}
if ($paramClass && $paramClass->isInstance($injection)) {
@@ -374,6 +385,10 @@ class InjectableFactory
/**
* @deprecated Use create or createWith methods instead.
*
* @template T of object
* @phpstan-param class-string<T> $className
* @phpstan-return T
*/
public function createByClassName(string $className, ?array $with = null): object
{
@@ -388,6 +403,8 @@ class InjectableFactory
{
$setList = [];
assert($obj instanceof Injectable);
$dependencyList = $obj->getDependencyList();
foreach ($dependencyList as $name) {