1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace NamespaceProtector\Event; |
||
6 | |||
7 | use Psr\EventDispatcher\EventDispatcherInterface; |
||
8 | use Psr\EventDispatcher\ListenerProviderInterface; |
||
9 | |||
10 | final class EventDispatcher implements EventDispatcherInterface |
||
11 | { |
||
12 | public function __construct(private ListenerProviderInterface $listenerProvider) |
||
13 | { |
||
14 | } |
||
15 | |||
16 | public function dispatch(object $event) |
||
17 | { |
||
18 | $this->listenerProvider->getListenersForEvent($event); |
||
19 | |||
20 | /** @var array<callable> */ |
||
21 | $listeners = $this->listenerProvider->getListenersForEvent($event); |
||
22 | |||
23 | array_map( |
||
24 | function (callable $listener) use ($event): void { |
||
25 | $listener($event); |
||
26 | }, |
||
27 | $listeners |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
28 | ); |
||
29 | |||
30 | return $event; |
||
31 | } |
||
32 | } |
||
33 |