-
Notifications
You must be signed in to change notification settings - Fork 439
/
Copy pathTopicsCommand.php
70 lines (58 loc) · 1.79 KB
/
TopicsCommand.php
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
66
67
68
69
70
<?php
namespace Enqueue\Symfony\Client\Meta;
use Enqueue\Client\Meta\TopicMetaRegistry;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableSeparator;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class TopicsCommand extends Command
{
protected static $defaultName = 'enqueue:topics';
/**
* @var TopicMetaRegistry
*/
private $topicRegistry;
/**
* @param TopicMetaRegistry $topicRegistry
*/
public function __construct(TopicMetaRegistry $topicRegistry)
{
parent::__construct(static::$defaultName);
$this->topicRegistry = $topicRegistry;
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setAliases([
'enq:m:t',
'debug:enqueue:topics',
])
->setDescription('A command shows all available topics and some information about them.')
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$table = new Table($output);
$table->setHeaders(['Topic', 'Description', 'processors']);
$count = 0;
$firstRow = true;
foreach ($this->topicRegistry->getTopicsMeta() as $topic) {
if (false == $firstRow) {
$table->addRow(new TableSeparator());
}
$table->addRow([$topic->getName(), $topic->getDescription(), implode(PHP_EOL, $topic->getProcessors())]);
++$count;
$firstRow = false;
}
$output->writeln(sprintf('Found %s topics', $count));
$output->writeln('');
$table->render();
}
}