The doc comment array<class-string,list<callable>> at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in array<class-string,list<callable>>.
Loading history...
15
private array $specificListeners = [];
16
17
16
/**
18
* @param list<callable> $genericListeners
19
16
*/
20
public function registerGenericListeners(array $genericListeners): void
21
{
22
$this->genericListeners = $genericListeners;
23
}
24
16
25
/**
26
16
* @param class-string $event
27
*/
28
public function registerSpecificListener(string $event, callable $listener): void
29
{
30
$this->specificListeners[$event][] = $listener;
31
}
32
6
33
public function dispatch(object $event): void
34
6
{
35
foreach ($this->genericListeners as $listener) {
36
$this->notifyListener($listener, $event);
37
26
}
38
39
26
foreach ($this->specificListeners[get_class($event)] ?? [] as $listener) {
40
12
$this->notifyListener($listener, $event);
41
}
42
}
43
26
44
14
private function notifyListener(callable $listener, object $event): void