diff --git a/src/Illuminate/Console/Application.php b/src/Illuminate/Console/Application.php index a6deeb61309e..5e1770fd450e 100755 --- a/src/Illuminate/Console/Application.php +++ b/src/Illuminate/Console/Application.php @@ -27,6 +27,13 @@ class Application extends SymfonyApplication implements ApplicationContract */ protected $lastOutput; + /** + * The console application bootstrappers. + * + * @var array + */ + protected static $bootstrappers = []; + /** * Create a new Artisan console application. * @@ -44,6 +51,20 @@ public function __construct(Container $laravel, Dispatcher $events, $version) $this->setCatchExceptions(false); $events->fire(new Events\ArtisanStarting($this)); + + $this->bootstrap(); + } + + /** + * Bootstrap the console application. + * + * @return void + */ + protected function bootstrap() + { + foreach (static::$bootstrappers as $bootstrapper) { + $bootstrapper($this); + } } /** @@ -169,4 +190,15 @@ public function getLaravel() { return $this->laravel; } + + /** + * Register an application starting bootstrapper. + * + * @param \Closure $callback + * @return void + */ + public static function starting(\Closure $callback) + { + static::$bootstrappers[] = $callback; + } } diff --git a/src/Illuminate/Foundation/Console/Kernel.php b/src/Illuminate/Foundation/Console/Kernel.php index 5cbbf20809bd..0426f4a30be8 100644 --- a/src/Illuminate/Foundation/Console/Kernel.php +++ b/src/Illuminate/Foundation/Console/Kernel.php @@ -8,7 +8,6 @@ use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Console\Application as Artisan; -use Illuminate\Console\Events\ArtisanStarting; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Console\Kernel as KernelContract; use Symfony\Component\Debug\Exception\FatalThrowableError; @@ -181,8 +180,8 @@ public function command($signature, Closure $callback) { $command = new ClosureCommand($signature, $callback); - $this->app['events']->listen(ArtisanStarting::class, function ($event) use ($command) { - $event->artisan->add($command); + Artisan::starting(function ($artisan) use ($command) { + $artisan->add($command); }); return $command; diff --git a/src/Illuminate/Support/ServiceProvider.php b/src/Illuminate/Support/ServiceProvider.php index 0403afb90491..33f68a37c426 100755 --- a/src/Illuminate/Support/ServiceProvider.php +++ b/src/Illuminate/Support/ServiceProvider.php @@ -2,7 +2,7 @@ namespace Illuminate\Support; -use Illuminate\Console\Events\ArtisanStarting; +use Illuminate\Console\Application as Artisan; abstract class ServiceProvider { @@ -176,13 +176,8 @@ public function commands($commands) { $commands = is_array($commands) ? $commands : func_get_args(); - // To register the commands with Artisan, we will grab each of the arguments - // passed into the method and listen for Artisan "start" event which will - // give us the Artisan console instance which we will give commands to. - $events = $this->app['events']; - - $events->listen(ArtisanStarting::class, function ($event) use ($commands) { - $event->artisan->resolveCommands($commands); + Artisan::starting(function ($artisan) use ($commands) { + $artisan->resolveCommands($commands); }); }