2020-03-20 23:46:58 +00:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 09:26:18 +01:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2020-05-20 17:53:53 +01:00
|
|
|
// {{{ License
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
// }}}
|
|
|
|
|
2020-03-21 20:18:05 +00:00
|
|
|
/**
|
|
|
|
* Command to search for event by pattern
|
|
|
|
*
|
|
|
|
* @package GNUsocial
|
|
|
|
* @category Command
|
|
|
|
*
|
2021-02-19 23:29:43 +00:00
|
|
|
* @author Hugo Sales <hugo@hsal.es>
|
|
|
|
* @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
|
2020-03-21 20:18:05 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2020-03-20 23:46:58 +00:00
|
|
|
namespace App\Command;
|
|
|
|
|
|
|
|
use Functional as F;
|
2020-05-10 21:43:15 +01:00
|
|
|
use ReflectionFunction;
|
2020-07-06 21:47:14 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
2020-03-20 23:46:58 +00:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
|
|
|
2021-07-28 22:08:07 +01:00
|
|
|
/**
|
|
|
|
* Get a list of event registered in GNU social
|
|
|
|
*
|
|
|
|
* Testing unfeasable, since it outputs stuff
|
|
|
|
*
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
*/
|
2020-07-06 21:47:14 +01:00
|
|
|
class ListEventsCommand extends Command
|
2020-03-20 23:46:58 +00:00
|
|
|
{
|
|
|
|
protected static $defaultName = 'app:events';
|
|
|
|
private EventDispatcherInterface $dispatcher;
|
|
|
|
|
|
|
|
public function __construct(EventDispatcherInterface $dispatcher)
|
|
|
|
{
|
2020-07-06 21:47:14 +01:00
|
|
|
parent::__construct();
|
2020-03-20 23:46:58 +00:00
|
|
|
$this->dispatcher = $dispatcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function configure()
|
|
|
|
{
|
2020-07-06 21:47:14 +01:00
|
|
|
$this->setDefinition([new InputArgument('pattern', InputArgument::OPTIONAL, 'An event pattern to look for')])
|
2021-10-10 09:26:18 +01:00
|
|
|
->setDescription('Search for an event')
|
|
|
|
->setHelp(
|
|
|
|
<<<'EOF'
|
|
|
|
The <info>%command.name%</info> command displays GNU social event listeners:
|
2020-07-06 21:47:14 +01:00
|
|
|
|
2021-10-10 09:26:18 +01:00
|
|
|
<info>php %command.full_name%</info>
|
2020-07-06 21:47:14 +01:00
|
|
|
|
2021-10-10 09:26:18 +01:00
|
|
|
To get specific listeners for an event, specify its name:
|
2020-07-06 21:47:14 +01:00
|
|
|
|
2021-10-10 09:26:18 +01:00
|
|
|
<info>php %command.full_name% kernel.request</info>
|
|
|
|
EOF,
|
|
|
|
);
|
2020-03-20 23:46:58 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 19:48:40 +00:00
|
|
|
/**
|
|
|
|
* Execute the command, outputing a list of GNU social events
|
|
|
|
*/
|
2020-03-20 23:46:58 +00:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
{
|
|
|
|
$patterm = $input->getArgument('pattern') ?? 'GNUsocial.*';
|
|
|
|
$listeners = $this->dispatcher->getListeners();
|
2021-10-10 09:26:18 +01:00
|
|
|
$listeners = F\select(
|
|
|
|
$listeners,
|
|
|
|
fn ($_, $key, $__) => preg_match('/' . $patterm . '/', $key),
|
|
|
|
);
|
2020-03-20 23:46:58 +00:00
|
|
|
|
2020-11-06 19:48:40 +00:00
|
|
|
ksort($listeners);
|
2020-03-20 23:46:58 +00:00
|
|
|
foreach ($listeners as $event => $listener) {
|
2020-11-06 19:48:40 +00:00
|
|
|
$event = explode('.', $event)[1];
|
|
|
|
$output->writeln("<info>Event '<options=bold>{$event}</options=bold>':</info>");
|
2020-03-20 23:46:58 +00:00
|
|
|
foreach ($listener as $c) {
|
2020-05-10 21:43:15 +01:00
|
|
|
$r = new ReflectionFunction($c);
|
2020-08-03 21:51:24 +01:00
|
|
|
$m = $r->getStaticVariables()['handler'];
|
2021-10-10 09:26:18 +01:00
|
|
|
$output->writeln("\t" . \get_class($m[0]) . '::' . $m[1]);
|
2020-03-20 23:46:58 +00:00
|
|
|
}
|
2020-11-06 19:48:40 +00:00
|
|
|
$output->writeln('');
|
2020-03-20 23:46:58 +00:00
|
|
|
}
|
2020-07-06 21:47:14 +01:00
|
|
|
|
2020-08-03 21:51:24 +01:00
|
|
|
if (!$input->hasArgument('pattern')) {
|
|
|
|
$io = new SymfonyStyle($input, $output);
|
|
|
|
$options = [];
|
|
|
|
$helper = new DescriptorHelper();
|
|
|
|
$options['output'] = $io;
|
|
|
|
$helper->describe($io, null, $options);
|
|
|
|
}
|
2020-03-20 23:46:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|