Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
arai-ta committed Feb 1, 2024
1 parent d2f5199 commit e7c72a1
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Definition/Definition.php
Expand Up @@ -21,8 +21,6 @@ class Definition implements ArgumentResolverInterface, DefinitionInterface
use ArgumentResolverTrait;
use ContainerAwareTrait;

private const RECURSIVE_RESOLVE_MAX = 10;

/**
* @var string
*/
Expand Down Expand Up @@ -59,9 +57,9 @@ class Definition implements ArgumentResolverInterface, DefinitionInterface
protected $resolved;

/**
* @var int
* @var bool
*/
protected $recursiveResolveCount = 0;
protected $isAlreadySearched = false;

/**
* @param string $id
Expand Down Expand Up @@ -193,15 +191,17 @@ public function resolveNew()
$container = null;
}

// stop recursive resolving
if ($this->isAlreadySearched) {
throw new NotFoundException(
sprintf('Alias or class "%s" did not found.', $concrete)
);
}

// if we still have a string, try to pull it from the container
// this allows for `alias -> alias -> ... -> concrete
if (is_string($concrete) && $container instanceof ContainerInterface && $container->has($concrete)) {
if ($this->recursiveResolveCount++ > self::RECURSIVE_RESOLVE_MAX) {
throw new NotFoundException(
sprintf('Alias "%s" did not found or alias too deep.', $concrete)
);
}

$this->isAlreadySearched = true;
$concrete = $container->get($concrete);
}

Expand Down

0 comments on commit e7c72a1

Please sign in to comment.