Giter Club home page Giter Club logo

Comments (14)

GrahamCampbell avatar GrahamCampbell commented on May 18, 2024 4

Auto detecting commands is easy. Here's some code lifted from from kernel of an app I have:

    /**
     * Get the artisan application instance.
     *
     * @return \Illuminate\Console\Application
     */
    protected function getArtisan()
    {
        if (!$this->artisan) {
            $this->artisan = new Application($this->app, $this->events, $this->app->version());

            // put any other commands in this array
            // in this case, the deploy command here is Bugsnag\BugsnagLaravel\Commands\DeployCommand
            $commands = [DeployCommand::class];

            foreach (glob(app_path('Console//Commands').'/*.php') as $file) {
                $commands[] = 'App\\Console\\Commands\\'.basename($file, '.php');
            }

            $this->artisan->resolveCommands($commands);
        }

        return $this->artisan;
    }

from laravel-zero.

nunomaduro avatar nunomaduro commented on May 18, 2024 3

@jkniest I am definitely interested in that.

That means, all commands in the app/Commands directory (the file path would be configurable) would be registered automatically without the need to register them manually in the config file.

This should be an array of directories on the config. Any none, the framework will automatically assign app/Commands.

I will leave this issue open while we wait for the development. Thanks for the help!

from laravel-zero.

ashleyhood avatar ashleyhood commented on May 18, 2024 2

@jkniest your right, I did mix the two up 😄

Should really read and understand before posting 😆

from laravel-zero.

nunomaduro avatar nunomaduro commented on May 18, 2024 2

@jkniest I will see! Thanks for the feedback!

from laravel-zero.

jkniest avatar jkniest commented on May 18, 2024 1

Ok, cool.. I will start this evening with the development :)

from laravel-zero.

nunomaduro avatar nunomaduro commented on May 18, 2024 1

This feature just got implemented in: laravel-zero/framework@dec0346 👍

from laravel-zero.

rookie0 avatar rookie0 commented on May 18, 2024

WANTED 😄

from laravel-zero.

introwit avatar introwit commented on May 18, 2024

Makes sense for me. 👍 @nunomaduro your thoughts?

from laravel-zero.

GrahamCampbell avatar GrahamCampbell commented on May 18, 2024

Note that this is not exactly high performance, but fast enough if you don't have many commands, and if you don't care about bootstrapping time, compared to with http where you might.

The performant way to do this would be to have a command that cached the classes to register, similar to how route caching works in the core framework.

from laravel-zero.

jkniest avatar jkniest commented on May 18, 2024

I agree with the performance part but the caching commands would add new documentation and explanation, because many users will be confused (at first) why there old commands are still running, even if their not in the $command array anymore (because their cached).

As an alternative, we could make the auto detection optional. For example a bool value in the config file, wether they want to use it..

I think in most console application's it doesn't matter much, because they don't have that much commands and if they do have so many, they could simply remove the folder from the detection-array and register all commands manually.

What are your thoughts?

from laravel-zero.

ashleyhood avatar ashleyhood commented on May 18, 2024

I would of thought this would be similar to Laravel 5.5 package autoload that parses the composer/installed.php so when you add a new package through composer the post update script will trigger a command to rebuild the cache.

This would be additional to the current way of adding commands.

from laravel-zero.

jkniest avatar jkniest commented on May 18, 2024

@ashleyhood Yeah.. but in the current state laravel loads all commands when the application starts, not when composer is updating / dumping the autoload.

I think you are mixing here two different features: Package autoloading & Command autoloading :)

from laravel-zero.

nunomaduro avatar nunomaduro commented on May 18, 2024

@jkniest Do you have news on this? Otherwise I don't mind of implementing this. 😊

from laravel-zero.

jkniest avatar jkniest commented on May 18, 2024

Oh sorry.. I haven't much time in the last days.. Feel free to implement this feature.. :-)

from laravel-zero.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.