Skip to content

Commit

Permalink
add method to auto register a directory of commands
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jul 17, 2017
1 parent 92e2aff commit 2e7ddca
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Illuminate/Foundation/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Closure;
use Exception;
use Throwable;
use Illuminate\Support\Str;
use Symfony\Component\Finder\Finder;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Console\Application as Artisan;
Expand Down Expand Up @@ -188,6 +190,33 @@ public function command($signature, Closure $callback)
return $command;
}

/**
* Register all of the commands in the given directory.
*
* @param string $path
* @return void
*/
protected function load($path)
{
if (! is_dir($path)) {
return;
}

$namespace = $this->app->getNamespace();

foreach ((new Finder)->in($path)->files() as $command) {
$command = $namespace.str_replace(
['/', '.php'],
['\\', ''],
Str::after($command->getPathname(), app_path().'/')
);

Artisan::starting(function ($artisan) use ($command) {
$artisan->resolve($command);
});
}
}

/**
* Register the given command with the console application.
*
Expand Down

1 comment on commit 2e7ddca

@m1guelpf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taylorotwell Could this go into 5.4? This shouldn't be breaking...

Please sign in to comment.