| Total Complexity | 4 |
| Total Lines | 28 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | class Event |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var array<string, list<callable>> |
||
|
|
|||
| 18 | */ |
||
| 19 | private array $listeners = []; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Register a listener for event |
||
| 23 | */ |
||
| 24 | public function on(string $event, callable $callable): void |
||
| 25 | { |
||
| 26 | if (! array_key_exists($event, $this->listeners)) { |
||
| 27 | $this->listeners[$event] = []; |
||
| 28 | } |
||
| 29 | |||
| 30 | $this->listeners[$event][] = $callable; |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Trigger event |
||
| 35 | */ |
||
| 36 | public function emit(string $event, ...$args) |
||
| 42 | } |
||
| 43 | } |
||
| 45 |