brick/reflection
Low-level PHP 8.1+ helpers extending native reflection. ReflectionTools can list all instance methods/properties across inheritance (including private parents), get class hierarchies, and create reflections for any callable with meaningful function names.
Strengths:
Reflection* classes (e.g., hierarchical method/property traversal, namespace-aware import resolution).ReflectionTools and ImportResolver are decoupled, enabling targeted adoption (e.g., use ImportResolver for annotation parsing without ReflectionTools).getClassHierarchy() avoids redundant ReflectionClass instantiation).Weaknesses:
0.x.y versioning signals instability; critical for long-lived projects (e.g., Laravel core or monolithic apps).ImportResolver’s edge cases).Laravel Compatibility:
Illuminate\Support\Facades\Reflection (no conflicts).app()->make(ReflectionTools::class)).booting (e.g., caching reflection data during service initialization) or registered events (e.g., dynamic method injection).RefreshDatabase, Mockery) via reflection-based test generation.Example Use Cases:
ProxyManager to inspect method signatures at runtime.Collection/QueryBuilder macros based on reflected methods.dd() with ReflectionTools::exportFunctionSignature() for formatted output.0.7.0’s final classes) may force refactoring if upgrading.ImportResolver’s namespace resolution might fail in complex Laravel setups (e.g., dynamic namespaces, traits).0.7.*: Pin to the latest stable cycle to avoid 0.x.0 surprises.Cache facade) for repeated calls.Illuminate\Contracts)?app()->makeWith()) or phpDocumentor/reflection-docblock suffice?composer require brick/reflection integration.ReflectionTools/ImportResolver as singletons:
$this->app->singleton(ReflectionTools::class, fn() => new ReflectionTools());
Reflection::getClassHierarchy()).php artisan make:command --reflect).exportFunctionSignature() for PHPDoc generation.ReflectionTools.getClassHierarchy() for service containers).ImportResolver for annotation parsing).deprecate() helper to warn about obsolete code.getClassMethods() handles traits natively; test with Laravel’s Illuminate\Support\Traits (e.g., Concerns).DynamicClassLoader or ProxyManager.ImportResolver can parse Laravel’s custom annotations (e.g., @route, @middleware).ImportResolver assumes standard PSR-4 autoloading; may fail with custom namespace logic (e.g., App\Providers\RouteServiceProvider aliases).boot() or middleware if profiling shows bottlenecks.| Step | Action | Owner | Dependencies |
|---|---|---|---|
| 1. Evaluation | Benchmark custom vs. package reflection for 3 critical paths. | Backend Engineer | None |
| 2. Setup | Add brick/reflection to composer.json and lock to 0.7.*. |
PM/DevOps | Composer |
| 3. Pilot | Replace one reflection utility (e.g., a debug helper). | Senior Developer | Step 2 |
| 4. Integration | Register ReflectionTools in AppServiceProvider. |
Backend Engineer | Laravel 10+ |
| 5. Testing | Update tests to use the package (e.g., mock private methods). | QA Engineer | Step 4 |
| 6. Documentation | Add package usage to internal docs (e.g., "Reflection Best Practices"). | Tech Writer | Step 5 |
| 7. Rollout | Deprecate custom reflection code in favor of the package. | Team Lead | Steps 1–6 |
ImportResolver failing silently).exportFunctionSignature() vs. native reflection).ImportResolver not finding classes).ReflectionExceptions.Illuminate\Support\Facades\Cache):
$cacheKey = 'reflection:'.md5($className);
return Cache::remember($cacheKey, 60, fn() => ReflectionTools::getClassHierarchy($class));
debug() mode).How can I help you explore Laravel packages today?