From 8a1177cab4c35320edd56157d4acec5956321745 Mon Sep 17 00:00:00 2001 From: yousef kadah Date: Tue, 21 Oct 2025 18:08:52 +0300 Subject: [PATCH 1/2] [12.x] Add confirmation prompts to cache commands This commit adds the ConfirmableTrait to config:cache, route:cache, view:cache, and event:cache commands to prevent accidental cache regeneration in production environments. Changes: - Added ConfirmableTrait to all cache commands - Added --force option to bypass confirmation prompts - Converted $name property to $signature to support options - Added confirmToProceed() check before cache operations The confirmation prompt only appears when running in production environment, following the same pattern used in other destructive commands like key:generate. Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../Foundation/Console/ConfigCacheCommand.php | 12 ++++++++++-- .../Foundation/Console/EventCacheCommand.php | 10 +++++++++- .../Foundation/Console/RouteCacheCommand.php | 12 ++++++++++-- .../Foundation/Console/ViewCacheCommand.php | 10 +++++++++- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Foundation/Console/ConfigCacheCommand.php b/src/Illuminate/Foundation/Console/ConfigCacheCommand.php index cedf0309dabc..bc87648533ad 100644 --- a/src/Illuminate/Foundation/Console/ConfigCacheCommand.php +++ b/src/Illuminate/Foundation/Console/ConfigCacheCommand.php @@ -3,6 +3,7 @@ namespace Illuminate\Foundation\Console; use Illuminate\Console\Command; +use Illuminate\Console\ConfirmableTrait; use Illuminate\Contracts\Console\Kernel as ConsoleKernelContract; use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Arr; @@ -13,12 +14,15 @@ #[AsCommand(name: 'config:cache')] class ConfigCacheCommand extends Command { + use ConfirmableTrait; + /** - * The console command name. + * The name and signature of the console command. * * @var string */ - protected $name = 'config:cache'; + protected $signature = 'config:cache + {--force : Force the operation to run when in production}'; /** * The console command description. @@ -55,6 +59,10 @@ public function __construct(Filesystem $files) */ public function handle() { + if (! $this->confirmToProceed()) { + return; + } + $this->callSilent('config:clear'); $config = $this->getFreshConfiguration(); diff --git a/src/Illuminate/Foundation/Console/EventCacheCommand.php b/src/Illuminate/Foundation/Console/EventCacheCommand.php index 4b6edf67d8ad..0718d1d74ddb 100644 --- a/src/Illuminate/Foundation/Console/EventCacheCommand.php +++ b/src/Illuminate/Foundation/Console/EventCacheCommand.php @@ -3,18 +3,22 @@ namespace Illuminate\Foundation\Console; use Illuminate\Console\Command; +use Illuminate\Console\ConfirmableTrait; use Illuminate\Foundation\Support\Providers\EventServiceProvider; use Symfony\Component\Console\Attribute\AsCommand; #[AsCommand(name: 'event:cache')] class EventCacheCommand extends Command { + use ConfirmableTrait; + /** * The name and signature of the console command. * * @var string */ - protected $signature = 'event:cache'; + protected $signature = 'event:cache + {--force : Force the operation to run when in production}'; /** * The console command description. @@ -30,6 +34,10 @@ class EventCacheCommand extends Command */ public function handle() { + if (! $this->confirmToProceed()) { + return; + } + $this->callSilent('event:clear'); file_put_contents( diff --git a/src/Illuminate/Foundation/Console/RouteCacheCommand.php b/src/Illuminate/Foundation/Console/RouteCacheCommand.php index 9b8632af50b2..00269d4609fe 100644 --- a/src/Illuminate/Foundation/Console/RouteCacheCommand.php +++ b/src/Illuminate/Foundation/Console/RouteCacheCommand.php @@ -3,6 +3,7 @@ namespace Illuminate\Foundation\Console; use Illuminate\Console\Command; +use Illuminate\Console\ConfirmableTrait; use Illuminate\Contracts\Console\Kernel as ConsoleKernelContract; use Illuminate\Filesystem\Filesystem; use Illuminate\Routing\RouteCollection; @@ -11,12 +12,15 @@ #[AsCommand(name: 'route:cache')] class RouteCacheCommand extends Command { + use ConfirmableTrait; + /** - * The console command name. + * The name and signature of the console command. * * @var string */ - protected $name = 'route:cache'; + protected $signature = 'route:cache + {--force : Force the operation to run when in production}'; /** * The console command description. @@ -51,6 +55,10 @@ public function __construct(Filesystem $files) */ public function handle() { + if (! $this->confirmToProceed()) { + return; + } + $this->callSilent('route:clear'); $routes = $this->getFreshApplicationRoutes(); diff --git a/src/Illuminate/Foundation/Console/ViewCacheCommand.php b/src/Illuminate/Foundation/Console/ViewCacheCommand.php index 3eacc26fd769..2e14b89528eb 100644 --- a/src/Illuminate/Foundation/Console/ViewCacheCommand.php +++ b/src/Illuminate/Foundation/Console/ViewCacheCommand.php @@ -3,6 +3,7 @@ namespace Illuminate\Foundation\Console; use Illuminate\Console\Command; +use Illuminate\Console\ConfirmableTrait; use Illuminate\Support\Collection; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Output\OutputInterface; @@ -12,12 +13,15 @@ #[AsCommand(name: 'view:cache')] class ViewCacheCommand extends Command { + use ConfirmableTrait; + /** * The name and signature of the console command. * * @var string */ - protected $signature = 'view:cache'; + protected $signature = 'view:cache + {--force : Force the operation to run when in production}'; /** * The console command description. @@ -33,6 +37,10 @@ class ViewCacheCommand extends Command */ public function handle() { + if (! $this->confirmToProceed()) { + return; + } + $this->callSilent('view:clear'); $this->paths()->each(function ($path) { From 3787b3bd46444ad8fe22df00f1872c19d072fcec Mon Sep 17 00:00:00 2001 From: yousef kadah Date: Tue, 21 Oct 2025 19:06:22 +0300 Subject: [PATCH 2/2] Add missing @throws annotations to improve IDE support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds missing @throws annotations to methods that throw exceptions but were not properly documented. This improves: - IDE autocomplete and warnings - PHPStan/Psalm static analysis - Developer experience Changes: - Config/Repository: Added @throws InvalidArgumentException to string(), integer(), float(), boolean(), and array() methods - Redis/Connections/PacksPhpRedisValues: Added @throws RuntimeException and UnexpectedValueException to pack() method - Session/SymfonySessionDecorator: Added @throws BadMethodCallException to registerBag(), getBag(), and getMetadataBag() methods 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/Illuminate/Config/Repository.php | 10 ++++++++++ .../Redis/Connections/PacksPhpRedisValues.php | 3 +++ src/Illuminate/Session/SymfonySessionDecorator.php | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/src/Illuminate/Config/Repository.php b/src/Illuminate/Config/Repository.php index 08801213a0f3..5086b18dab74 100644 --- a/src/Illuminate/Config/Repository.php +++ b/src/Illuminate/Config/Repository.php @@ -84,6 +84,8 @@ public function getMany($keys) * @param string $key * @param (\Closure():(string|null))|string|null $default * @return string + * + * @throws \InvalidArgumentException */ public function string(string $key, $default = null): string { @@ -104,6 +106,8 @@ public function string(string $key, $default = null): string * @param string $key * @param (\Closure():(int|null))|int|null $default * @return int + * + * @throws \InvalidArgumentException */ public function integer(string $key, $default = null): int { @@ -124,6 +128,8 @@ public function integer(string $key, $default = null): int * @param string $key * @param (\Closure():(float|null))|float|null $default * @return float + * + * @throws \InvalidArgumentException */ public function float(string $key, $default = null): float { @@ -144,6 +150,8 @@ public function float(string $key, $default = null): float * @param string $key * @param (\Closure():(bool|null))|bool|null $default * @return bool + * + * @throws \InvalidArgumentException */ public function boolean(string $key, $default = null): bool { @@ -164,6 +172,8 @@ public function boolean(string $key, $default = null): bool * @param string $key * @param (\Closure():(array|null))|array|null $default * @return array + * + * @throws \InvalidArgumentException */ public function array(string $key, $default = null): array { diff --git a/src/Illuminate/Redis/Connections/PacksPhpRedisValues.php b/src/Illuminate/Redis/Connections/PacksPhpRedisValues.php index a64c4f4ce3dc..0c890dd62039 100644 --- a/src/Illuminate/Redis/Connections/PacksPhpRedisValues.php +++ b/src/Illuminate/Redis/Connections/PacksPhpRedisValues.php @@ -34,6 +34,9 @@ trait PacksPhpRedisValues * * @param array $values * @return array + * + * @throws \RuntimeException + * @throws \UnexpectedValueException */ public function pack(array $values): array { diff --git a/src/Illuminate/Session/SymfonySessionDecorator.php b/src/Illuminate/Session/SymfonySessionDecorator.php index 365aca670333..54a899ea7a7e 100644 --- a/src/Illuminate/Session/SymfonySessionDecorator.php +++ b/src/Illuminate/Session/SymfonySessionDecorator.php @@ -161,6 +161,8 @@ public function isStarted(): bool /** * {@inheritdoc} + * + * @throws \BadMethodCallException */ public function registerBag(SessionBagInterface $bag): void { @@ -169,6 +171,8 @@ public function registerBag(SessionBagInterface $bag): void /** * {@inheritdoc} + * + * @throws \BadMethodCallException */ public function getBag(string $name): SessionBagInterface { @@ -177,6 +181,8 @@ public function getBag(string $name): SessionBagInterface /** * {@inheritdoc} + * + * @throws \BadMethodCallException */ public function getMetadataBag(): MetadataBag {