diff --git a/Annotated/CustomTypeResolvers.php b/Annotated/CustomTypeResolvers.php new file mode 100644 index 0000000..92ec2b1 --- /dev/null +++ b/Annotated/CustomTypeResolvers.php @@ -0,0 +1,33 @@ + $resolvers + */ + public function __construct( + private readonly iterable $resolvers, + ) {} + + public function resolveCustomType(string $unresolvedName, array $typeArguments, TypeContext $context): ?Type + { + foreach ($this->resolvers as $resolver) { + $type = $resolver->resolveCustomType($unresolvedName, $typeArguments, $context); + + if ($type !== null) { + return $type; + } + } + + return null; + } +} diff --git a/TyphoonReflector.php b/TyphoonReflector.php index ce5bb1d..ce4d291 100644 --- a/TyphoonReflector.php +++ b/TyphoonReflector.php @@ -20,7 +20,7 @@ use Typhoon\DeclarationId\TemplateId; use Typhoon\PhpStormReflectionStubs\PhpStormStubsLocator; use Typhoon\Reflection\Annotated\CustomTypeResolver; -use Typhoon\Reflection\Annotated\NullCustomTypeResolver; +use Typhoon\Reflection\Annotated\CustomTypeResolvers; use Typhoon\Reflection\Exception\DeclarationNotFound; use Typhoon\Reflection\Internal\Cache\Cache; use Typhoon\Reflection\Internal\Cache\InMemoryPsr16Cache; @@ -70,14 +70,15 @@ final class TyphoonReflector /** * @param ?iterable $locators + * @param iterable $customTypeResolvers */ public static function build( ?iterable $locators = null, ?CacheInterface $cache = null, - CustomTypeResolver $customTypeResolver = new NullCustomTypeResolver(), + iterable $customTypeResolvers = [], ?Parser $phpParser = null, ): self { - $phpDocReflector = new PhpDocReflector($customTypeResolver); + $phpDocReflector = new PhpDocReflector(new CustomTypeResolvers($customTypeResolvers)); return new self( codeReflector: new CodeReflector(