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