Skip to content

Commit e40474b

Browse files
committed
OptimizedPsrAutoloaderLocator - look for other symbols in already scanned files
1 parent 46f51e7 commit e40474b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Reflection/BetterReflection/SourceLocator/OptimizedPsrAutoloaderLocator.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
class OptimizedPsrAutoloaderLocator implements SourceLocator
1414
{
1515

16+
/** @var array<string, OptimizedSingleFileSourceLocator> */
17+
private array $locators = [];
18+
1619
public function __construct(
1720
private PsrAutoloaderMapping $mapping,
1821
private OptimizedSingleFileSourceLocatorRepository $optimizedSingleFileSourceLocatorRepository,
@@ -22,16 +25,28 @@ public function __construct(
2225

2326
public function locateIdentifier(Reflector $reflector, Identifier $identifier): ?Reflection
2427
{
28+
foreach ($this->locators as $locator) {
29+
$reflection = $locator->locateIdentifier($reflector, $identifier);
30+
if ($reflection === null) {
31+
continue;
32+
}
33+
34+
return $reflection;
35+
}
36+
2537
foreach ($this->mapping->resolvePossibleFilePaths($identifier) as $file) {
2638
if (!is_file($file)) {
2739
continue;
2840
}
2941

30-
$reflection = $this->optimizedSingleFileSourceLocatorRepository->getOrCreate($file)->locateIdentifier($reflector, $identifier);
42+
$locator = $this->optimizedSingleFileSourceLocatorRepository->getOrCreate($file);
43+
$reflection = $locator->locateIdentifier($reflector, $identifier);
3144
if ($reflection === null) {
3245
continue;
3346
}
3447

48+
$this->locators[$file] = $locator;
49+
3550
return $reflection;
3651
}
3752

0 commit comments

Comments
 (0)