-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathDebugCommand.php
More file actions
65 lines (52 loc) · 1.78 KB
/
DebugCommand.php
File metadata and controls
65 lines (52 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace Bernard\BernardBundle\Command;
use Bernard\Router;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* @final since 2.1
*/
class DebugCommand extends Command
{
/**
* @var Router
*/
private $router;
public function __construct($router = null)
{
parent::__construct();
if (!$router instanceof Router) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead as this will be the only supported way in bernard bundle 3.0. ', __METHOD__), E_USER_DEPRECATED);
$this->setName(null === $router ? 'bernard:debug' : $router);
return;
}
$this->router = $router;
}
public function configure()
{
$this
->setName('bernard:debug')
->setDescription('Displays a table of receivers that are registered with "bernard.receiver" tag.')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
if (null === $this->router) {
$this->router = $this->getContainer()->get('bernard.router');
}
$r = new \ReflectionProperty($this->router, 'receivers');
$r->setAccessible(true);
$rows = [];
foreach ($r->getValue($this->router) as $key => $val) {
$rows[] = [$key, $val];
}
$table = new Table($output);
$table
->setHeaders(['Message', 'Service'])
->addRows($rows)
->render()
;
}
}