From 1301afced05f9810342c1ff9055a42bf441d80e8 Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Mon, 1 Apr 2019 20:28:16 +0200 Subject: [PATCH 1/2] add event:list command --- .../Foundation/Console/EventListCommand.php | 53 +++++++++++++++++++ .../Providers/ArtisanServiceProvider.php | 14 +++++ 2 files changed, 67 insertions(+) create mode 100644 src/Illuminate/Foundation/Console/EventListCommand.php diff --git a/src/Illuminate/Foundation/Console/EventListCommand.php b/src/Illuminate/Foundation/Console/EventListCommand.php new file mode 100644 index 000000000000..e3d590a4c891 --- /dev/null +++ b/src/Illuminate/Foundation/Console/EventListCommand.php @@ -0,0 +1,53 @@ +table(['Event', 'Listeners'], $this->getEvents()); + } + + /** + * Get all of the events and listeners configured for the application. + * + * @return array + */ + protected function getEvents() + { + $events = []; + + foreach ($this->laravel->getProviders(EventServiceProvider::class) as $provider) { + $providerEvents = array_merge($provider->discoverEvents(), $provider->listens()); + + $events = array_merge_recursive($events, $providerEvents); + } + + return collect($events)->map(function ($value, $key) { + return ['Event' => $key, 'Listeners' => implode("\n", $value)]; + })->values()->toArray(); + } +} diff --git a/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php b/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php index 9ea9bb08987f..5c50d1942f81 100755 --- a/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php @@ -2,6 +2,7 @@ namespace Illuminate\Foundation\Providers; +use Illuminate\Foundation\Console\EventListCommand; use Illuminate\Support\ServiceProvider; use Illuminate\Queue\Console\TableCommand; use Illuminate\Auth\Console\AuthMakeCommand; @@ -93,6 +94,7 @@ class ArtisanServiceProvider extends ServiceProvider implements DeferrableProvid 'Environment' => 'command.environment', 'EventCache' => 'command.event.cache', 'EventClear' => 'command.event.clear', + 'EventList' => 'command.event.list', 'KeyGenerate' => 'command.key.generate', 'Migrate' => 'command.migrate', 'MigrateFresh' => 'command.migrate.fresh', @@ -430,6 +432,18 @@ protected function registerEventClearCommand() }); } + /** + * Register the command. + * + * @return void + */ + protected function registerEventListCommand() + { + $this->app->singleton('command.event.list', function () { + return new EventListCommand(); + }); + } + /** * Register the command. * From 0885282b1eacf4fd7e3bcd559b31ec4b7a71036f Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Mon, 1 Apr 2019 20:30:33 +0200 Subject: [PATCH 2/2] style fix --- src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php b/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php index 5c50d1942f81..110d5e89a663 100755 --- a/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php @@ -2,7 +2,6 @@ namespace Illuminate\Foundation\Providers; -use Illuminate\Foundation\Console\EventListCommand; use Illuminate\Support\ServiceProvider; use Illuminate\Queue\Console\TableCommand; use Illuminate\Auth\Console\AuthMakeCommand; @@ -20,6 +19,7 @@ use Illuminate\Foundation\Console\OptimizeCommand; use Illuminate\Foundation\Console\RuleMakeCommand; use Illuminate\Foundation\Console\TestMakeCommand; +use Illuminate\Foundation\Console\EventListCommand; use Illuminate\Foundation\Console\EventMakeCommand; use Illuminate\Foundation\Console\ModelMakeCommand; use Illuminate\Foundation\Console\RouteListCommand;