mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
type fix
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user