imanghafoori/laravel-smart-facades
Cache::strategy('redis')->get()), which aligns well with systems requiring runtime-configurable behavior (e.g., caching, logging, or API clients). This is particularly useful in microservices, feature flags, or A/B testing where behavior must switch without code changes.Cache, Log, Mail) with context-aware methods, reducing boilerplate for conditional logic. Fits systems where facades are heavily used (e.g., legacy Laravel apps or monolithic services).Cache::strategy() checks for registered strategies). Negligible for most use cases but could matter in high-throughput systems (e.g., real-time APIs).if ($config['use_redis']) { Cache::redis()->... })?app()->bind() or context managers achieve the same with less abstraction?Cache, Log, Mail).// Before
if ($config['cache_driver'] === 'redis') {
Cache::store('redis')->get('key');
}
// After
Cache::strategy('redis')->get('key');
strategy() calls.partialMock for facades).app()->bind() for static strategy binding.if-else or switch blocks for facade behavior.Cache::strategy('redis')->get() fails—is it the strategy or the cache?).Log::strategy('slack')->error()).AppServiceProvider to fail fast on missing strategies.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Unregistered strategy called | Silent failure or default behavior | Validate strategies in boot() |
| Strategy throws exception | Unclear error source | Wrap in try-catch or custom facade |
| Facade macro conflicts | Package breaks existing facades | Test with Facade::clearResolvedInstance() |
| Laravel upgrade breaks macros | Package stops working | Fork and maintain locally if needed |
| Performance degradation | High latency in critical paths | Fallback to manual conditionals |
Cache::strategy('redis')->remember()).How can I help you explore Laravel packages today?