Completed
Push — master ( c2ba48...1fd225 )
by Markus
14s queued 12s
created

EventQueueProducer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
namespace Jellyfish\Event;
4
5
use Jellyfish\Queue\QueueClientInterface;
6
7
class EventQueueProducer implements EventQueueProducerInterface
8
{
9
    /**
10
     * @var \Jellyfish\Event\EventMapperInterface
11
     */
12
    protected $eventMapper;
13
14
    /**
15
     * @var \Jellyfish\Queue\QueueClientInterface
16
     */
17
    protected $queueClient;
18
19
    /**
20
     * @var \Jellyfish\Event\EventQueueNameGeneratorInterface
21
     */
22
    protected $eventQueueNameGenerator;
23
24
    /**
25
     * @param \Jellyfish\Event\EventMapperInterface $eventMapper
26
     * @param \Jellyfish\Event\EventQueueNameGeneratorInterface $eventQueueNameGenerator
27
     * @param \Jellyfish\Queue\QueueClientInterface $queueClient
28
     */
29
    public function __construct(
30
        EventMapperInterface $eventMapper,
31
        EventQueueNameGeneratorInterface $eventQueueNameGenerator,
32
        QueueClientInterface $queueClient
33
    ) {
34
        $this->eventMapper = $eventMapper;
35
        $this->eventQueueNameGenerator = $eventQueueNameGenerator;
36
        $this->queueClient = $queueClient;
37
    }
38
39
    /**
40
     * @param string $eventName
41
     * @param \Jellyfish\Event\EventInterface $event
42
     * @param \Jellyfish\Event\EventListenerInterface $listener
43
     *
44
     * @return \Jellyfish\Event\EventQueueProducerInterface
45
     */
46
    public function enqueueEvent(
47
        string $eventName,
48
        EventInterface $event,
49
        EventListenerInterface $listener
50
    ): EventQueueProducerInterface {
51
        $eventQueueName = $this->eventQueueNameGenerator->generate($eventName, $listener->getIdentifier());
52
        $message = $this->eventMapper->toMessage($event);
53
54
        $this->queueClient->sendMessage($eventQueueName, $message);
55
56
        return $this;
57
    }
58
}
59