1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | namespace Porta\Psr14Event; |
8: | |
9: | use Psr\EventDispatcher\EventDispatcherInterface; |
10: | use Psr\EventDispatcher\ListenerProviderInterface; |
11: | use Psr\EventDispatcher\StoppableEventInterface; |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | class Dispatcher implements EventDispatcherInterface |
19: | { |
20: | |
21: | protected ListenerProviderInterface $provider; |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | public function __construct(ListenerProviderInterface $provider) |
30: | { |
31: | $this->provider = $provider; |
32: | } |
33: | |
34: | |
35: | |
36: | |
37: | |
38: | |
39: | |
40: | public function dispatch(object $event): object |
41: | { |
42: | foreach ($this->provider->getListenersForEvent($event) as $listener) { |
43: | if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) { |
44: | return $event; |
45: | } |
46: | $listener($event); |
47: | } |
48: | return $event; |
49: | } |
50: | } |
51: | |