Skip to content

Commit

Permalink
add PHP 8 support to resolver getDependencies()
Browse files Browse the repository at this point in the history
  • Loading branch information
kevindees authored Aug 10, 2022
1 parent 4534c2a commit 121b632
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Core/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,17 @@ public function getDependencies($parameters)
{
$dependencies = [];
foreach ($parameters as $parameter) {
$dependency = $parameter->getClass();
if ( ! $dependency ) {
$dependency = $parameter->getType();

$isBuiltInType = false;
if($dependency instanceof \ReflectionNamedType) {
$isBuiltInType = $dependency->isBuiltin();
}

if ( ! $dependency || !$dependency instanceof \ReflectionNamedType || $isBuiltInType ) {
$dependencies[] = $this->resolveNonClass($parameter);
} else {
$dependencies[] = $this->resolve($dependency->name);
$dependencies[] = $this->resolve($dependency->getName());
}
}
return $dependencies;
Expand All @@ -70,6 +76,6 @@ public function resolveNonClass(\ReflectionParameter $parameter)
if ($parameter->isDefaultValueAvailable()) {
return $parameter->getDefaultValue();
}
throw new \Exception('Cannot resolve using reflection');
throw new \Exception('Resolver failed because there is no default value for the parameter: $' . $parameter->getName());
}
}
}

0 comments on commit 121b632

Please sign in to comment.