Skip to content

Commit

Permalink
OptimizedPsrAutoloaderLocator - look for other symbols in already sca…
Browse files Browse the repository at this point in the history
…nned files
  • Loading branch information
ondrejmirtes committed May 4, 2022
1 parent 46f51e7 commit e40474b
Showing 1 changed file with 16 additions and 1 deletion.
Expand Up @@ -13,6 +13,9 @@
class OptimizedPsrAutoloaderLocator implements SourceLocator
{

/** @var array<string, OptimizedSingleFileSourceLocator> */
private array $locators = [];

public function __construct(
private PsrAutoloaderMapping $mapping,
private OptimizedSingleFileSourceLocatorRepository $optimizedSingleFileSourceLocatorRepository,
Expand All @@ -22,16 +25,28 @@ public function __construct(

public function locateIdentifier(Reflector $reflector, Identifier $identifier): ?Reflection
{
foreach ($this->locators as $locator) {
$reflection = $locator->locateIdentifier($reflector, $identifier);
if ($reflection === null) {
continue;
}

return $reflection;
}

foreach ($this->mapping->resolvePossibleFilePaths($identifier) as $file) {
if (!is_file($file)) {
continue;
}

$reflection = $this->optimizedSingleFileSourceLocatorRepository->getOrCreate($file)->locateIdentifier($reflector, $identifier);
$locator = $this->optimizedSingleFileSourceLocatorRepository->getOrCreate($file);
$reflection = $locator->locateIdentifier($reflector, $identifier);
if ($reflection === null) {
continue;
}

$this->locators[$file] = $locator;

return $reflection;
}

Expand Down

0 comments on commit e40474b

Please sign in to comment.