Completed
Push — master ( 664783...554f9d )
by
unknown
15:59
created

ProduceCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 15
cts 15
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * Sends a given message to the message bus.
5
 */
6
7
namespace Graviton\RabbitMqBundle\Command;
8
9
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Console\Input\InputArgument;
13
14
/**
15
 * Sends a given message to the message bus.
16
 *
17
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
18
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
19
 * @link     http://swisscom.ch
20
 */
21
class ProduceCommand extends ContainerAwareCommand
22
{
23
24
    /**
25
     * Configures command
26
     *
27
     * @return void
28
     */
29 4
    protected function configure()
30
    {
31 4
        parent::configure();
32 4
        $this->setName('graviton:message:produce')
33 4
            ->setDescription(
34 4
                'Puts a message onto the RabbitMQ channel.'
35
            )
36 4
            ->addArgument(
37 4
                'message',
38 4
                InputArgument::REQUIRED,
39 4
                'The message to be sent e.g. "bundle.resource.update"'
40
            )
41 4
            ->addArgument(
42 4
                'data',
43 4
                InputArgument::OPTIONAL,
44 4
                'JSON formatted data to send to with the message.',
45 4
                '{}'
46
            );
47 4
    }
48
49
    /**
50
     * @param InputInterface  $input  The input
51
     * @param OutputInterface $output The output
52
     *
53
     * @return void
54
     */
55
    protected function execute(InputInterface $input, OutputInterface $output)
56
    {
57
        $producer = $this->getContainer()->get('graviton.message.jobproducer');
58
        $producer->setContentType('application/json');
59
        $producer->publish(
60
            $input->getArgument('data'),
61
            $input->getArgument('message')
62
        );
63
    }
64
}
65