You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 16, 2021. It is now read-only.
Resolve Contracts\Console\Kernel through IOC and try to call all() method to get a list of all registered artisan commands
Problem
all() method on Foundation\Console\Kernel is not returning auto registered commands.
Analysis
unlike the call() method which makes a call to commands() method to make sure all commands are loaded, all() method doesn't do any such thing
public function call($command, array $parameters = [], $outputBuffer = null)
{
$this->bootstrap();
if (! $this->commandsLoaded) {
$this->commands();
$this->commandsLoaded = true;
}
return $this->getArtisan()->call($command, $parameters, $outputBuffer);
}
all() method is missing the logic to make sure all commands have been loaded
public function all()
{
$this->bootstrap();
return $this->getArtisan()->all();
}
The reason being a call to load(DIR.'\Commands') in app/Console/Kernel.php
Possible Solutions
Modify all() method to include the logic (of making sure that all commands have been loaded) as follows:
public function all()
{
$this->bootstrap();
if (! $this->commandsLoaded) {
$this->commands();
$this->commandsLoaded = true;
}
return $this->getArtisan()->all();
}
--- OR ---
Move the logic (of making sure that all commands have been loaded) to bootstrap method and remove it from every other method which already calls bootstrap
public function bootstrap()
{
if (! $this->app->hasBeenBootstrapped()) {
$this->app->bootstrapWith($this->bootstrappers());
}
// If we are calling an arbitrary command from within the application, we'll load
// all of the available deferred providers which will make all of the commands
// available to an application. Otherwise the command will not be available.
$this->app->loadDeferredProviders();
if (! $this->commandsLoaded) {
$this->commands();
$this->commandsLoaded = true;
}
}
The text was updated successfully, but these errors were encountered:
Scenario
Resolve
Contracts\Console\Kernel
through IOC and try to call all() method to get a list of all registered artisan commandsProblem
all() method on
Foundation\Console\Kernel
is not returning auto registered commands.Analysis
unlike the call() method which makes a call to commands() method to make sure all commands are loaded, all() method doesn't do any such thing
all() method is missing the logic to make sure all commands have been loaded
The reason being a call to load(DIR.'\Commands') in app/Console/Kernel.php
Possible Solutions
--- OR ---
The text was updated successfully, but these errors were encountered: