Skip to content

Commit

Permalink
[5.x] Fix issues with Please commands on Laravel 11 (#9877)
Browse files Browse the repository at this point in the history
Co-authored-by: duncanmcclean <[email protected]>
  • Loading branch information
duncanmcclean and duncanmcclean authored Apr 12, 2024
1 parent 0c078d8 commit d645e80
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Console/Please/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 27 additions & 4 deletions src/Console/Please/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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__;
}
}

0 comments on commit d645e80

Please sign in to comment.