Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Add event:list command #28085

Merged
merged 2 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/Illuminate/Foundation/Console/EventListCommand.php
Original file line number Diff line number Diff line change
@@ -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());
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we be calling $provider->discoveredEvents() here? I am seeing discovered events in event:list even with event auto-discovery disabled.

Copy link
Member

Choose a reason for hiding this comment

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

Ping @themsaid


$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
Original file line number Diff line number Diff line change
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