| 1 | <?php |
||
| 9 | final class EventContainer implements EventContainerInterface |
||
| 10 | { |
||
| 11 | /** @psalm-var array<string,list<callable>> */ |
||
| 12 | private $listeners = array(); |
||
| 13 | |||
| 14 | 9 | public function __construct() |
|
| 17 | |||
| 18 | /** |
||
| 19 | * @param string $event |
||
| 20 | * @param callable $handler |
||
| 21 | * |
||
| 22 | * @return void |
||
| 23 | */ |
||
| 24 | 5 | public function addListener($event, $handler) |
|
| 25 | { |
||
| 26 | 5 | if(!\in_array($event, Events::getEvents(), true)) { |
|
| 27 | 1 | throw new \InvalidArgumentException(sprintf('Unsupported event %s!', $event)); |
|
| 28 | } |
||
| 29 | |||
| 30 | 4 | if(!array_key_exists($event, $this->listeners)) { |
|
| 31 | 4 | $this->listeners[$event] = array(); |
|
| 32 | 4 | } |
|
| 33 | |||
| 34 | 4 | $this->listeners[$event][] = $handler; |
|
| 35 | 4 | } |
|
| 36 | |||
| 37 | /** |
||
| 38 | * @param string $event |
||
| 39 | * |
||
| 40 | * @psalm-return list<callable> |
||
| 41 | */ |
||
| 42 | 5 | public function getListeners($event) |
|
| 46 | |||
| 47 | /** |
||
| 48 | * @param string $name |
||
| 49 | * |
||
| 50 | * @return bool |
||
| 51 | */ |
||
| 52 | 5 | private function hasEvent($name) |
|
| 56 | } |
||
| 57 |