illuminate/reflection
Illuminate Reflection provides lightweight helpers around PHP’s Reflection API, used by Laravel to inspect classes, methods, and parameters. It supports resolving type information and attributes to power features like container autowiring, routing, and validation.
The illuminate/reflection package provides a higher-level, developer-friendly API for PHP's reflection capabilities—designed specifically to work seamlessly with Laravel’s container, conventions, and coding patterns. To begin, install it via Composer (composer require illuminate/reflection) and import the main facade or class (Illuminate\Support\Reflector). The first use case is often resolving class dependencies in a standardized way—e.g., checking if a class is instantiable, resolving its constructor dependencies, or retrieving parameter types with Laravel-aware defaults (like resolving Request $request from the container). Start by reading Reflector::getConstructor() and Reflector::resolvable().
Developers commonly use Reflector to:
Reflector::make() or Reflector::resolve(), especially when building dynamic controllers, middleware, or command handlers.Reflector::isConcrete().@inject or #[Inject] attributes (via Reflector::getMethodParameters()).Example workflow: Discovering all classes in a namespace, filtering for those implementing a specific interface, and resolving only those that are instantiable using Reflector::canBeInstantiated().
Reflection* classes—it wraps them with Laravel-specific logic. For deep inspection (e.g., docblocks, custom attributes), fall back to PHP’s ReflectionClass where Reflector is too high-level.Reflector::make() and resolve() do not use the container directly—you must pass the container manually (e.g., Reflector::make($container, $class)) or use Container::make() unless using the helper proxies.Reflector, you can subclass it or register custom logic in your service providers, but the class is final in practice—rely on its stable API.composer.json (PSR-4 autoloading) and use Reflector::canBeInstantiated($class) before instantiation.Reflector::getParameters() with withDefaults: true to see how Laravel infers defaults from the container (e.g., string $env = 'local' → 'local' if bound).How can I help you explore Laravel packages today?