|
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 MiddlewareChain $chain |
|
34
|
|
|
* @param EventBusInterface $bus_publisher |
|
35
|
|
|
*/ |
|
36
|
3 |
|
public function __construct(MiddlewareChain $chain, EventBusInterface $bus_publisher) |
|
37
|
|
|
{ |
|
38
|
3 |
|
$this->bus_publisher = $bus_publisher; |
|
39
|
3 |
|
$this->chain = $chain; |
|
40
|
3 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param EventInterface $event |
|
44
|
|
|
*/ |
|
45
|
2 |
|
public function publish(EventInterface $event) |
|
46
|
|
|
{ |
|
47
|
2 |
|
$this->chain->run($event); |
|
48
|
2 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param AggregateEventsInterface $aggregator |
|
52
|
|
|
*/ |
|
53
|
1 |
|
public function pullAndPublish(AggregateEventsInterface $aggregator) |
|
54
|
|
|
{ |
|
55
|
1 |
|
foreach ($aggregator->pullEvents() as $event) { |
|
56
|
1 |
|
$this->publish($event); |
|
57
|
1 |
|
} |
|
58
|
1 |
|
} |
|
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
|
1 |
|
public function getRegisteredEventListeners() |
|
67
|
|
|
{ |
|
68
|
1 |
|
return $this->bus_publisher->getRegisteredEventListeners(); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|