Created
December 13, 2021 23:28
-
-
Save henriqueramos/5d7d504a7e5312751a878fa5fc930bbf to your computer and use it in GitHub Desktop.
List pkp-lib 3.4 events
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
<?php | |
/** | |
* @file tools/event/listEvents.php | |
* | |
* Copyright (c) 2014-2021 Simon Fraser University | |
* Copyright (c) 2003-2021 John Willinsky | |
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | |
* | |
* @class listEvents | |
* @ingroup tools | |
* | |
* @brief CLI tool to list all events registered on the system | |
*/ | |
namespace PKP\tools\event; | |
use PKP\cliTool\CommandLineTool; | |
use PKP\core\PKPContainer; | |
use PKP\core\PKPEventServiceProvider; | |
use Symfony\Component\Console\Helper\Table; | |
use Illuminate\Console\OutputStyle; | |
use Symfony\Component\Console\Input\StringInput; | |
use Symfony\Component\Console\Output\StreamOutput; | |
define('APP_ROOT', dirname(dirname(dirname(dirname(dirname(__FILE__)))))); | |
require(APP_ROOT . '/tools/bootstrap.inc.php'); | |
class listEvents extends CommandLineTool | |
{ | |
/** | |
* Print command usage information. | |
*/ | |
public function usage() | |
{ | |
echo "Command-line tool to list all events registered on the system \n" | |
. "Usage:\n" | |
. "\t{$this->scriptName}: List all events registered\n"; | |
} | |
/** | |
* Parse and execute list event command | |
*/ | |
public function execute() | |
{ | |
$eventServiceProvider = app() | |
->makeWith( | |
PKPEventServiceProvider::class, | |
['app' => PKPContainer::getInstance()] | |
); | |
$events = []; | |
$rawEvents = $eventServiceProvider->getEvents(); | |
foreach($rawEvents as $event => $listeners) { | |
$events[] = [$event, implode(', ', $listeners)]; | |
} | |
$output = new OutputStyle( | |
new StringInput(''), | |
new StreamOutput(fopen('php://stdout', 'w')) | |
); | |
$table = new Table($output); | |
$table | |
->setHeaders(['Event', 'Listeners']) | |
->setRows($events); | |
$table->render(); | |
} | |
} | |
$tool = new listEvents($argv ?? []); | |
$tool->execute(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment