Total Complexity | 7 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
9 | final class ConfigurableEventDispatcher implements EventDispatcherInterface |
||
10 | { |
||
11 | /** @var array<callable> */ |
||
12 | private array $genericListeners = []; |
||
13 | |||
14 | /** @var array<class-string,list<callable>> */ |
||
|
|||
15 | private array $specificListeners = []; |
||
16 | |||
17 | 13 | public function __construct() |
|
18 | { |
||
19 | 13 | } |
|
20 | |||
21 | /** |
||
22 | * @param list<callable> $genericListeners |
||
23 | */ |
||
24 | 13 | public function registerGenericListeners(array $genericListeners): void |
|
27 | } |
||
28 | /** |
||
29 | * @param class-string $event |
||
30 | */ |
||
31 | 6 | public function registerSpecificListener(string $event, callable $listener): void |
|
32 | { |
||
33 | 6 | $this->specificListeners[$event][] = $listener; |
|
34 | } |
||
35 | |||
36 | 33 | public function dispatch(object $event): void |
|
37 | { |
||
38 | 33 | foreach ($this->genericListeners as $listener) { |
|
39 | 20 | $this->notifyListener($listener, $event); |
|
40 | } |
||
41 | |||
42 | 33 | foreach ($this->specificListeners[get_class($event)] ?? [] as $listener) { |
|
43 | 6 | $this->notifyListener($listener, $event); |
|
44 | } |
||
45 | } |
||
46 | |||
47 | 26 | private function notifyListener(callable $listener, object $event): void |
|
50 | } |
||
51 | } |
||
52 |