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

EventQueueWorker   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A start() 0 8 4
1
<?php
2
3
namespace Jellyfish\Event;
4
5
class EventQueueWorker implements EventQueueWorkerInterface
6
{
7
    /**
8
     * @var \Jellyfish\Event\EventQueueConsumerInterface
9
     */
10
    protected $eventQueueConsumer;
11
    /**
12
     * @var \Jellyfish\Event\EventDispatcherInterface
13
     */
14
    protected $eventDispatcher;
15
16
    /**
17
     * @param \Jellyfish\Event\EventDispatcherInterface $eventDispatcher
18
     * @param \Jellyfish\Event\EventQueueConsumerInterface $eventQueueConsumer
19
     */
20
    public function __construct(
21
        EventDispatcherInterface $eventDispatcher,
22
        EventQueueConsumerInterface $eventQueueConsumer
23
    ) {
24
        $this->eventDispatcher = $eventDispatcher;
25
        $this->eventQueueConsumer = $eventQueueConsumer;
26
    }
27
28
    /**
29
     * @return void
30
     */
31
    public function start(): void
32
    {
33
        $listeners = $this->eventDispatcher->getListeners(EventListenerInterface::TYPE_ASYNC);
34
35
        while (true) {
36
            foreach ($listeners as $eventName => $listenersPerEvent) {
37
                foreach ($listenersPerEvent as $listenerIdentifier => $listener) {
38
                    $this->eventQueueConsumer->dequeueEventAsProcess($eventName, $listenerIdentifier);
39
                }
40
            }
41
        }
42
    }
43
}
44