1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace PHPStan\BetterReflection\SourceLocator\Type;
6:
7: use PHPStan\BetterReflection\Identifier\Identifier;
8: use PHPStan\BetterReflection\Identifier\IdentifierType;
9: use PHPStan\BetterReflection\Reflection\Reflection;
10: use PHPStan\BetterReflection\Reflector\Reflector;
11:
12: use function array_map;
13: use function array_merge;
14:
15: class AggregateSourceLocator implements SourceLocator
16: {
17: /**
18: * @var list<SourceLocator>
19: */
20: private $sourceLocators = [];
21: /** @param list<SourceLocator> $sourceLocators */
22: public function __construct(array $sourceLocators = [])
23: {
24: $this->sourceLocators = $sourceLocators;
25: }
26:
27: public function locateIdentifier(Reflector $reflector, Identifier $identifier): ?\PHPStan\BetterReflection\Reflection\Reflection
28: {
29: foreach ($this->sourceLocators as $sourceLocator) {
30: $located = $sourceLocator->locateIdentifier($reflector, $identifier);
31:
32: if ($located) {
33: return $located;
34: }
35: }
36:
37: return null;
38: }
39:
40: /**
41: * {@inheritDoc}
42: */
43: public function locateIdentifiersByType(Reflector $reflector, IdentifierType $identifierType): array
44: {
45: return array_merge([], ...array_map(static function (SourceLocator $sourceLocator) use ($reflector, $identifierType) : array {
46: return $sourceLocator->locateIdentifiersByType($reflector, $identifierType);
47: }, $this->sourceLocators));
48: }
49: }
50: