Skip to content

Commit

Permalink
Refactor DefinitionStorage (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
yiiliveext committed Nov 1, 2021
1 parent 953b3ac commit 731eeb4
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/DefinitionStorage.php
Expand Up @@ -11,6 +11,7 @@
use ReflectionUnionType;
use RuntimeException;
use Yiisoft\Definitions\Exception\CircularReferenceException;
use Yiisoft\Definitions\Infrastructure\DefinitionExtractor;

/**
* Stores service definitions and checks if a definition could be instantiated.
Expand Down Expand Up @@ -96,20 +97,13 @@ private function isResolvable(string $id, array $building): bool
}

try {
$reflectionClass = new ReflectionClass($id);
} catch (ReflectionException $e) {
$dependencies = DefinitionExtractor::getInstance()->fromClassName($id);
} catch (\Throwable $e) {
$this->buildStack += $building + [$id => 1];
return false;
}

if (!$reflectionClass->isInstantiable()) {
$this->buildStack += $building + [$id => 1];
return false;
}

$constructor = $reflectionClass->getConstructor();

if ($constructor === null) {
if ($dependencies === []) {
$this->definitions[$id] = $id;
return true;
}
Expand All @@ -118,7 +112,8 @@ private function isResolvable(string $id, array $building): bool
$building[$id] = 1;

try {
foreach ($constructor->getParameters() as $parameter) {
foreach ($dependencies as $dependency) {
$parameter = $dependency->getReflection();
$type = $parameter->getType();

if ($parameter->isVariadic() || $parameter->isOptional()) {
Expand Down

0 comments on commit 731eeb4

Please sign in to comment.