codememory/reflection
Cacheable alternative to PHP’s Reflection API. Uses a Symfony Cache adapter to store class metadata (names, methods, properties, types, attributes) for faster repeat reflection in production, with a dev mode toggle via ReflectorManager.
Reflection API, which can be costly for large codebases or high-traffic systems.Cache component (v7.1+), which is already a dependency in Laravel via symfony/cache. Compatible with Laravel’s native caching (e.g., Illuminate\Cache) via adapters like FileCache, RedisCache, or DatabaseCache.ReflectionClass, ReflectionProperty, etc., with a drop-in facade or service provider. Example:
// app/Providers/AppServiceProvider.php
public function register(): void {
$this->app->singleton(ReflectorManager::class, fn() =>
new ReflectorManager(
Cache::store('file')->getAdapter(),
app()->environment('local')
)
);
}
app()->makeWith() or new ReflectionClass()).#[Cacheable], #[Middleware]), reducing redundant reflection calls during request processing.Cache::tags(['reflection']) to invalidate on config:clear or route:clear.Optimizer or a custom event listener to clear caches on file changes (e.g., updated: *).isDev flag should map to Laravel’s app()->isLocal() or config('app.debug').symfony/cache stats (e.g., Cache::getAdapter()->getStats()).memory debug bar extension.ReflectionAttribute (if needed).#[Middleware], Eloquent model bootstrapping) to quantify gains.Reflection + APCu (if enabled).cache/reflection_*.php) or global (shared across environments)?Reflection if caching fails (e.g., disk full, permission issues).Bootstrap/HandleFatalErrors to auto-clear caches on fatal reflection errors?Container to auto-wrap reflection calls (e.g., app()->reflectorFor())?ReflectorManager::shouldReturnMock()).ReflectorManager as a singleton in Laravel’s container:
// config/reflection.php
'cache' => [
'driver' => 'file', // or 'redis', 'database'
'path' => storage_path('framework/cache/reflection'),
],
Reflection facade for ergonomic usage:
// app/Facades/Reflection.php
public static function class(string $class): ClassReflector {
return app(ReflectorManager::class)->getReflector($class);
}
Attribute system to auto-register reflection caches for annotated classes.config('reflection.enabled')).Illuminate\Support\Manager, Illuminate\Container) with the cached reflector.Container::build() to use ReflectorManager for constructor resolution.new Reflection* calls with Reflection::class() or app(ReflectorManager::class).debugbar).spatie/laravel-permission, laravel-excel). Most should work unchanged, but some may need cache invalidation hooks.Illuminate\Contracts\Proxy (e.g., Eloquent, API resources) since reflection is only used at generation time.xdebug, opcache, or APCu (though APCu may reduce gains).storage/framework/cache/reflection is writable.ReflectorManager to the container with environment-aware caching.php artisan tinker with reflection benchmarks).Cache::getAdapter()->getStats().Illuminate\Foundation\Bootstrap\LoadConfiguration (clear on config changes).Illuminate\Filesystem\Events\FileUpdated (clear on file changes).// app/Console/Commands/ClearReflectionCache.php
public function handle(): void {
Cache::forget('reflection-*');
}
codememory/reflection to specific versions in composer.json.Reflection::debug() method to dump cache stats and invalidation triggers.try {
return $reflector->getProperty('foo');
} catch (CacheException $
How can I help you explore Laravel packages today?