symfony/type-info
Symfony TypeInfo extracts and normalizes PHP type information. Resolve types from reflections or strings, build complex types via factories (nullable, list, generic, enum), cast to readable strings, and query identifiers/conditions for safer tooling and analysis.
php artisan make:model --api) by providing runtime validation.Type::list(Type::nullable(Type::object(User::class)))) for use in validation, serialization, or documentation generation.PropertyInfo, Serializer) or Laravel packages like spatie/laravel-data or nunomaduro/collision for type-safe data handling.TypeResolver::create() bound as a singleton).phpstan/phpdoc-parser for advanced string-based type resolution (e.g., resolving @var annotations). Laravel projects already using PHPStan/Psalm will have minimal overhead.ReflectionClass, ReflectionProperty, etc., enabling type extraction from models, controllers, or service classes without additional setup.TypeContextFactory (built-in cache support since v8.0.0-BETA1).symfony/type-info:^7.4 for Laravel 9/10 (PHP 8.1+).^8.0 only if PHP 8.4+ is supported.@template TKey of array-key).BackedEnum.phpstan/phpdoc-parser (~1MB) may be justified for projects using static analysis but could be overkill for lightweight APIs. Alternatives: Use only reflection-based resolution or StringTypeResolver for simple cases.Illuminate\Validation\Validator or a custom TypeGuard trait.TypeContextFactory cache or Redis).TypeInfo to generate PHPDoc stubs for untyped legacy code.TypeResolver against a suite of PHPDoc-annotated and unannotated classes.HasAttributes or custom validators)?Type::isSatisfiedBy() predicates.TypeResolver as a singleton in AppServiceProvider:
$this->app->singleton(TypeResolver::class, fn() => TypeResolver::create());
TypeInfo facade for convenience:
use Illuminate\Support\Facades\Facade;
class TypeInfo extends Facade { protected static function getFacadeAccessor() { return TypeResolver::class; } }
Usage: TypeInfo::resolve(new ReflectionProperty(User::class, 'email')).type:resolve command to dump type information for classes/properties (e.g., for debugging or documentation).Validator to enforce runtime types:
$validator->extend('type', fn($attr, $value, $params) => TypeInfo::resolve($params['expected_type'])->accepts($value));
spatie/laravel-arrayable or symfony/serializer to validate serialized data types.Type objects to OpenAPI types (e.g., Type::object(User::class) → User schema).phpstan/phpdoc-parser.TypeResolver::resolve(new ReflectionProperty(Model::class, 'id'))).TypeResolver to the service container.TypeInfo::getPropertyType(Model::class, 'name')).TypeContextFactory cache or Redis).TypeInfo.symfony/type-info:^7.4 (PHP 8.1+).^8.0 (PHP 8.4+).PropertyInfo) by using consistent versions.phpstan/phpdoc-parser conflicts by pinning versions in composer.json.StringTypeResolver unless PHPDoc annotations exist).TypeInfo").How can I help you explore Laravel packages today?