Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

[5.5] Auto registered commands are missing when calling all() method on Foundation\Console\Kernel #770

Closed
roshangautam opened this issue Aug 31, 2017 · 4 comments

Comments

@roshangautam
Copy link

Scenario

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

  1. 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 ---

  1. 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;
        }
    }
@m1guelpf
Copy link

ping @themsaid as this seems to be a bug rather than a feature suggestion.

@themsaid
Copy link
Member

laravel/framework#20863 Worked on that, thanks :)

@m1guelpf
Copy link

@roshangautam The PR was merged, this issue can be closed.

@roshangautam
Copy link
Author

Thanks guys.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants