Skip to content

Commit

Permalink
Merge pull request #28085 from themsaid/eventListCommand
Browse files Browse the repository at this point in the history
[5.8] Add event:list command
  • Loading branch information
taylorotwell committed Apr 1, 2019
2 parents 86f5352 + 0885282 commit c84e44d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/Illuminate/Foundation/Console/EventListCommand.php
@@ -0,0 +1,53 @@
<?php

namespace Illuminate\Foundation\Console;

use Illuminate\Console\Command;
use Illuminate\Foundation\Support\Providers\EventServiceProvider;

class EventListCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'event:list';

/**
* The console command description.
*
* @var string
*/
protected $description = "List the application's events and listeners";

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->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();
}
}
14 changes: 14 additions & 0 deletions src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php
Expand Up @@ -19,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;
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit c84e44d

Please sign in to comment.