1 | <?php |
||
25 | class EventBus extends Bus |
||
26 | { |
||
27 | const BUS_NAME = 'bus.event'; |
||
28 | |||
29 | /** |
||
30 | * @var EventDispatcher |
||
31 | */ |
||
32 | protected $dispatcher; |
||
33 | |||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $responses = array(); |
||
38 | |||
39 | /** |
||
40 | * Constructor. |
||
41 | * |
||
42 | * @param EventDispatcher|null $dispatcher |
||
43 | */ |
||
44 | public function __construct(EventDispatcher $dispatcher = null) |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | public function getName() |
||
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | public function registers(array $events) |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | public function register($event, $handler) |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | public function dispatchNow(MessageInterface $event) |
||
87 | { |
||
88 | if (!$event instanceof AbstractDomainEvent) { |
||
89 | throw new InvalidArgumentException(sprintf( |
||
90 | 'Domain event "%s" should implement \Borobudur\Cqrs\Message\AbstractDomainEvent', |
||
91 | get_class($event) |
||
92 | )); |
||
93 | } |
||
94 | |||
95 | $this->responses = array(); |
||
96 | $this->dispatcher->fireEvent(ltrim(get_class($event), '\\'), $event); |
||
97 | |||
98 | return $this->responses; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Get event handler. |
||
103 | * |
||
104 | * @param mixed $handler |
||
105 | * @param string $class |
||
106 | * |
||
107 | * @return Closure |
||
108 | */ |
||
109 | protected function getClosureHandler($handler, $class) |
||
124 | } |
||
125 |