Total Complexity | 6 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 | /** |
||
18 | * @param list<callable> $genericListeners |
||
19 | */ |
||
20 | public function registerGenericListeners(array $genericListeners): void |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * @param class-string $event |
||
27 | */ |
||
28 | public function registerSpecificListener(string $event, callable $listener): void |
||
29 | { |
||
30 | $this->specificListeners[$event][] = $listener; |
||
31 | } |
||
32 | |||
33 | public function dispatch(object $event): void |
||
34 | { |
||
35 | foreach ($this->genericListeners as $listener) { |
||
36 | $this->notifyListener($listener, $event); |
||
37 | } |
||
38 | |||
39 | foreach ($this->specificListeners[get_class($event)] ?? [] as $listener) { |
||
40 | $this->notifyListener($listener, $event); |
||
41 | } |
||
42 | } |
||
43 | |||
44 | private function notifyListener(callable $listener, object $event): void |
||
47 | } |
||
48 | } |
||
49 |