From 40d4a9191004129b8e3de26dcf22f5c75d9cfc0b Mon Sep 17 00:00:00 2001 From: agis Date: Sat, 12 Sep 2026 09:55:50 +0700 Subject: [PATCH] refactor(console): resolve handle()-or-fire() in Command::execute() (task 3.8) L13 Command runs handle() (or __invoke); fire() is removed. Make the fork's execute() prefer handle() and fall back to fire() during migration -- mirrors stock Command's runtime resolution and lets app commands converge to handle() one at a time. fire() dies at the Console swap. Fork-internal commands keep fire(): they run via the fallback and are replaced by stock illuminate/* commands at their package swaps, so renaming them now is wasted. Enforcement is app-side (grep guard on command classes) -- the resolution is runtime, not type-expressible. Ratchet event_fire baseline 4->3: Command::execute()'s `$this->fire()` is now `$this->{$method}()`, leaving only the 3 Queue Job::fire() (their own task). Fork suite 1644 green. Co-Authored-By: Claude Opus 4.8 (1M context) --- ci/convergence-baseline.txt | 2 +- src/Illuminate/Console/Command.php | 8 ++++-- tests/Console/ConsoleApplicationTest.php | 31 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/ci/convergence-baseline.txt b/ci/convergence-baseline.txt index cb12348ec..f1bb9a32d 100644 --- a/ci/convergence-baseline.txt +++ b/ci/convergence-baseline.txt @@ -2,7 +2,7 @@ # regenerate: ci/convergence-ratchet.sh --init src (hanya setelah count TURUN) array_first_last=0 route_uses_string=5 -event_fire=4 +event_fire=3 config_getEnvironment=3 where_raw=1 eloquent_lists=6 diff --git a/src/Illuminate/Console/Command.php b/src/Illuminate/Console/Command.php index 97276ac9f..feba65d28 100755 --- a/src/Illuminate/Console/Command.php +++ b/src/Illuminate/Console/Command.php @@ -110,10 +110,14 @@ public function run(InputInterface $input, OutputInterface $output): int */ protected function execute(InputInterface $input, OutputInterface $output): mixed { + // Prefer handle() (L13 idiom); fire() is the L4.2 fallback that dies at the Console swap. + // ponytail: fork mirror of stock Command's handle-or-__invoke resolution; app-side is grep-guarded. + $method = method_exists($this, 'handle') ? 'handle' : 'fire'; + // Symfony 5 removed support of returning null, so we cast the returned value as integer. - // In this case, void-returned fire() method will be casted to 0. + // A void-returned handle()/fire() is casted to 0. // @see https://github.com/symfony/console/blob/6.3/CHANGELOG.md#500 - return (int) $this->fire(); + return (int) $this->{$method}(); } /** diff --git a/tests/Console/ConsoleApplicationTest.php b/tests/Console/ConsoleApplicationTest.php index 71c494bb9..6a5813adb 100755 --- a/tests/Console/ConsoleApplicationTest.php +++ b/tests/Console/ConsoleApplicationTest.php @@ -3,6 +3,8 @@ use L4\Tests\BackwardCompatibleTestCase; use Mockery as m; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Output\NullOutput; class ConsoleApplicationTest extends BackwardCompatibleTestCase { @@ -66,4 +68,33 @@ public function testResolveCommandsCallsResolveForAllCommandsItsGivenViaArray() $app->resolveCommands(['foo', 'foo']); } + + public function testExecuteResolvesHandleThenFallsBackToFire() + { + $execute = new \ReflectionMethod(\Illuminate\Console\Command::class, 'execute'); + $execute->setAccessible(true); + $input = new ArrayInput([]); + $output = new NullOutput; + + // handle() is preferred (L13 idiom) + $this->assertSame(0, $execute->invoke(new ConsoleHandleStub, $input, $output)); + $this->assertEquals('handle', $_SERVER['__console.ran']); + + // fire() still runs as the L4.2 fallback when no handle() exists + $execute->invoke(new ConsoleFireStub, $input, $output); + $this->assertEquals('fire', $_SERVER['__console.ran']); + } + +} + +class ConsoleHandleStub extends \Illuminate\Console\Command +{ + protected $name = 'stub:handle'; + public function handle() { $_SERVER['__console.ran'] = 'handle'; } +} + +class ConsoleFireStub extends \Illuminate\Console\Command +{ + protected $name = 'stub:fire'; + public function fire() { $_SERVER['__console.ran'] = 'fire'; } }