Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Reflection Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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().

Implementation Patterns

Developers commonly use Reflector to:

  • Safely instantiate classes via Reflector::make() or Reflector::resolve(), especially when building dynamic controllers, middleware, or command handlers.
  • Inspect and process service provider bindings—e.g., checking whether a service is concrete or abstract using Reflector::isConcrete().
  • Integrate with Laravel’s service container, like resolving contextual bindings by inspecting class/method signatures and their @inject or #[Inject] attributes (via Reflector::getMethodParameters()).
  • Enable custom reflection utilities, such as generating API documentation from controller method signatures, or building command discovery tools that respect Laravel’s naming conventions.

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().

Gotchas and Tips

  • Not a replacement for native 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.
  • 💡 To extend 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.
  • 🔍 If getting “class not found” or “abstract class” errors, verify paths in composer.json (PSR-4 autoloading) and use Reflector::canBeInstantiated($class) before instantiation.
  • 🧪 Debug tip: Use Reflector::getParameters() with withDefaults: true to see how Laravel infers defaults from the container (e.g., string $env = 'local''local' if bound).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport