Completed
Push — master ( 67a91e...657487 )
by Peter
06:52
created

MiddlewareDomainEventBus::publish()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
namespace GpsLab\Component\Middleware\DomainEvent\Bus;
12
13
use GpsLab\Component\Middleware\Chain\MiddlewareChain;
14
use GpsLab\Domain\Event\Aggregator\AggregateEventsInterface;
15
use GpsLab\Domain\Event\Bus\EventBusInterface;
16
use GpsLab\Domain\Event\EventInterface;
17
use GpsLab\Domain\Event\Listener\ListenerCollection;
18
use GpsLab\Domain\Event\Listener\ListenerInterface;
19
20
class MiddlewareDomainEventBus implements EventBusInterface
21
{
22
    /**
23
     * @var EventBusInterface
24
     */
25
    private $bus_publisher;
26
27
    /**
28
     * @var MiddlewareChain
29
     */
30
    private $chain;
31
32
    /**
33
     * @param EventBusInterface $bus_publisher
34
     * @param MiddlewareChain   $chain
35
     */
36
    public function __construct(EventBusInterface $bus_publisher, MiddlewareChain $chain)
37
    {
38
        $this->bus_publisher = $bus_publisher;
39
        $this->chain = $chain;
40
    }
41
42
    /**
43
     * @param EventInterface $event
44
     */
45
    public function publish(EventInterface $event)
46
    {
47
        $this->chain->run($event);
48
    }
49
50
    /**
51
     * @param AggregateEventsInterface $aggregator
52
     */
53
    public function pullAndPublish(AggregateEventsInterface $aggregator)
54
    {
55
        foreach ($aggregator->pullEvents() as $event) {
56
            $this->publish($event);
57
        }
58
    }
59
60
    /**
61
     * Get the list of every EventListener defined in the EventBus.
62
     * This might be useful for debug.
63
     *
64
     * @return ListenerInterface[]|ListenerCollection
65
     */
66
    public function getRegisteredEventListeners()
67
    {
68
        return $this->bus_publisher->getRegisteredEventListeners();
69
    }
70
}
71