|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of slick/cqrs-tools |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Slick\CQRSTools\Infrastructure\Events; |
|
11
|
|
|
|
|
12
|
|
|
use League\Event\EmitterInterface; |
|
13
|
|
|
use Slick\CQRSTools\Event; |
|
14
|
|
|
use Slick\CQRSTools\Event\EventGenerator; |
|
15
|
|
|
use Slick\CQRSTools\Event\EventListener; |
|
16
|
|
|
use Slick\CQRSTools\Event\EventPublisher; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* LeagueEventPublisher |
|
20
|
|
|
* |
|
21
|
|
|
* @package Slick\CQRSTools\Infrastructure\Events |
|
22
|
|
|
*/ |
|
23
|
|
|
final class LeagueEventPublisher implements EventPublisher |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var EmitterInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $emitter; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Creates a League Event Publisher |
|
32
|
|
|
* |
|
33
|
|
|
* @param EmitterInterface $emitter |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(EmitterInterface $emitter) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->emitter = $emitter; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Publishes all event generated by provided generator |
|
42
|
|
|
* |
|
43
|
|
|
* @param EventGenerator $generator |
|
44
|
|
|
*/ |
|
45
|
|
|
public function publishEventsFrom(EventGenerator $generator): void |
|
46
|
|
|
{ |
|
47
|
|
|
$events = $generator->releaseEvents(); |
|
48
|
|
|
$this->emitter->emitBatch($events); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Publishes a single event |
|
53
|
|
|
* |
|
54
|
|
|
* @param Event $event |
|
55
|
|
|
*/ |
|
56
|
|
|
public function publish(Event $event): void |
|
57
|
|
|
{ |
|
58
|
|
|
$this->emitter->emit($event); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Adds an event listener |
|
63
|
|
|
* |
|
64
|
|
|
* @param string $event |
|
65
|
|
|
* @param EventListener $listener |
|
66
|
|
|
* @param int $priority |
|
67
|
|
|
*/ |
|
68
|
|
|
public function addListener( |
|
69
|
|
|
string $event, |
|
70
|
|
|
EventListener $listener, |
|
71
|
|
|
int $priority = EmitterInterface::P_NORMAL |
|
72
|
|
|
): void { |
|
73
|
|
|
$this->emitter->addListener($event, $listener, $priority); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: