Total Complexity | 6 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
5 | class EventService |
||
6 | { |
||
7 | |||
8 | protected $listeners = []; |
||
9 | |||
10 | /** |
||
11 | * @param string $eventName |
||
12 | * @param array $eventData |
||
13 | */ |
||
14 | public function trigger(string $eventName, array $eventData) |
||
15 | { |
||
16 | $listeners = $this->listeners[$eventName] ?? []; |
||
17 | foreach ($listeners as $listener) { |
||
18 | \call_user_func($listener[1], $eventData); |
||
19 | } |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * @param string $eventName |
||
24 | * @param callable $callable |
||
25 | * @param int $priority |
||
26 | */ |
||
27 | public function on(string $eventName, callable $callable, int $priority = 100) |
||
36 | }); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @return array |
||
41 | */ |
||
42 | public function getListeners(): array |
||
43 | { |
||
44 | return $this->listeners; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @param array $listeners |
||
49 | */ |
||
50 | public function setListeners(array $listeners) |
||
53 | } |
||
54 | } |
||
55 |