Completed
Push — master ( 59049f...fab486 )
by Tomasz
12:46 queued 02:08
created

RabbitMqSendDriver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
namespace Gendoria\CommandQueueRabbitMqDriverBundle\SendDriver;
4
5
use Isobar\CommandQueue\SendDriver\SendDriverInterface;
6
use Isobar\CommandQueue\Command\CommandInterface;
7
use JMS\Serializer\Serializer;
8
use OldSound\RabbitMqBundle\RabbitMq\Producer;
9
10
/**
11
 * Command queue send driver using RabbitMQ server.
12
 *
13
 * @author Tomasz Struczyński <[email protected]>
14
 */
15
class RabbitMqSendDriver implements SendDriverInterface
16
{
17
    /**
18
     * Serializer instance.
19
     *
20
     * @var Serializer
21
     */
22
    private $serializer;
23
24
    /**
25
     * Producer instance.
26
     *
27
     * @var Producer
28
     */
29
    private $producer;
30
31
    /**
32
     * Class constructor.
33
     *
34
     * @param Serializer $serializer
35
     * @param Producer   $producer
36
     */
37
    public function __construct(
38
        Serializer $serializer,
39
        Producer $producer
40
    ) {
41
        $this->serializer = $serializer;
42
        $this->producer = $producer;
43
    }
44
45
    /**
46
     * Send command using RabbitMQ server.
47
     *
48
     * {@inheritdoc}
49
     */
50
    public function send(CommandInterface $command)
51
    {
52
        $this->producer->publish(
53
            $this->serializer->serialize($command, 'json'),
54
            get_class($command),
55
            array(
56
                'application_headers' => array(
57
                    'x-class-name' => array(
58
                        'S',
59
                        get_class($command),
60
                    ),
61
                ),
62
            )
63
        );
64
    }
65
}
66