|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Jellyfish\Event\Command; |
|
6
|
|
|
|
|
7
|
|
|
use Jellyfish\Event\EventListenerProviderInterface; |
|
8
|
|
|
use Jellyfish\Serializer\SerializerInterface; |
|
9
|
|
|
use Symfony\Component\Console\Command\Command; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
|
|
14
|
|
|
class EventListenerGetCommand extends Command |
|
15
|
|
|
{ |
|
16
|
|
|
public const NAME = 'event:listener:get'; |
|
17
|
|
|
public const DESCRIPTION = 'Retrieve registered event listeners by type (JSON)'; |
|
18
|
|
|
/** |
|
19
|
|
|
* @var \Jellyfish\Event\EventListenerProviderInterface |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $eventListenerProvider; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var \Jellyfish\Serializer\SerializerInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $serializer; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param \Jellyfish\Event\EventListenerProviderInterface $eventListenerProvider |
|
30
|
|
|
* @param \Jellyfish\Serializer\SerializerInterface $serializer |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct( |
|
33
|
|
|
EventListenerProviderInterface $eventListenerProvider, |
|
34
|
|
|
SerializerInterface $serializer |
|
35
|
|
|
) { |
|
36
|
|
|
parent::__construct(); |
|
37
|
|
|
|
|
38
|
|
|
$this->eventListenerProvider = $eventListenerProvider; |
|
39
|
|
|
$this->serializer = $serializer; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return void |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function configure(): void |
|
46
|
|
|
{ |
|
47
|
|
|
parent::configure(); |
|
48
|
|
|
|
|
49
|
|
|
$this->setName(static::NAME); |
|
50
|
|
|
$this->setDescription(static::DESCRIPTION); |
|
51
|
|
|
|
|
52
|
|
|
$this->addArgument('type', InputArgument::REQUIRED, 'Type'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
|
57
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
|
58
|
|
|
* |
|
59
|
|
|
* @return int |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
62
|
|
|
{ |
|
63
|
|
|
$type = $input->getArgument('type'); |
|
64
|
|
|
|
|
65
|
|
|
$json = $this->serializer->serialize((object) $this->eventListenerProvider->getListenersByType($type), 'json'); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
$output->write($json); |
|
68
|
|
|
|
|
69
|
|
|
return 0; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|