Completed
Pull Request — 1.0 (#2)
by Jérémie
02:27
created

ConsumeCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Mouf\AmqpClient\Commands;
4
5
use Mouf\AmqpClient\Client;
6
use Mouf\AmqpClient\ConsumerService;
7
use Mouf\AmqpClient\Objects\Queue;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Input\InputOption;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class ConsumeCommand extends Command
14
{
15
16
    /**
17
     * @var ConsumerService
18
     */
19
    private $consumerService;
20
21
    /**
22
     * ConsumeCommand constructor.
23
     */
24
    public function __construct(ConsumerService $consumerService, $commandName = "amqp:consume", $description = null)
25
    {
26
        parent::__construct($commandName);
27
        $this->setDescription($description ?: 'Listen to messages from the AMQP bus (RabbitMQ)');
28
        $this->consumerService = $consumerService;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    protected function configure()
35
    {
36
        $this
37
            ->addOption('onlyone', 'o', InputOption::VALUE_NONE, 'Receives only one message and stop listening');
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    protected function execute(InputInterface $input, OutputInterface $output)
44
    {
45
        $this->consumerService->run($input->getOption('onlyone'));
46
    }
47
48
}