diff --git a/src/Console/Please/Application.php b/src/Console/Please/Application.php index ab4aa5a951..e4710a01b3 100644 --- a/src/Console/Please/Application.php +++ b/src/Console/Please/Application.php @@ -61,7 +61,7 @@ public function find(string $name): Command /** * Resolve deferred commands. */ - protected function resolveDeferredCommands() + public function resolveDeferredCommands() { foreach ($this->deferredCommands as $command) { $this->add($command); diff --git a/src/Console/Please/Kernel.php b/src/Console/Please/Kernel.php index 925d189143..bb66834954 100644 --- a/src/Console/Please/Kernel.php +++ b/src/Console/Please/Kernel.php @@ -4,7 +4,7 @@ use App\Console\Kernel as ConsoleKernel; use Statamic\Console\Please\Application as Please; -use Statamic\Statamic; +use Symfony\Component\EventDispatcher\EventDispatcher; class Kernel extends ConsoleKernel { @@ -15,8 +15,31 @@ class Kernel extends ConsoleKernel */ protected function getArtisan() { - return tap( - new Please($this->app, $this->events, Statamic::version()) - )->setName('Statamic'); + if (is_null($this->artisan)) { + $this->artisan = tap( + (new Please($this->app, $this->events, $this->app->version())) + ->resolveCommands($this->commands) + ->setContainerCommandLoader() + )->setName('Statamic'); + + if ($this->symfonyDispatcher instanceof EventDispatcher) { + $this->artisan->setDispatcher($this->symfonyDispatcher); + $this->artisan->setSignalsToDispatchEvent(); + } + } + + return $this->artisan; + } + + public function call($command, array $parameters = [], $outputBuffer = null) + { + $this->getArtisan()->resolveDeferredCommands(); + + return parent::call($command, $parameters, $outputBuffer); + } + + protected function shouldDiscoverCommands() + { + return get_class($this) === __CLASS__; } }