-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28085 from themsaid/eventListCommand
[5.8] Add event:list command
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
|
||
$events = array_merge_recursive($events, $providerEvents); | ||
} | ||
|
||
return collect($events)->map(function ($value, $key) { | ||
return ['Event' => $key, 'Listeners' => implode("\n", $value)]; | ||
})->values()->toArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters