* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Evenement; use InvalidArgumentException; use function count; use function array_keys; use function array_merge; use function array_search; use function array_unique; use function array_values; trait EventEmitterTrait { protected $listeners = []; protected $onceListeners = []; public function on($event, callable $listener) { if ($event === null) { throw new InvalidArgumentException('event name must not be null'); } if (!isset($this->listeners[$event])) { $this->listeners[$event] = []; } $this->listeners[$event][] = $listener; return $this; } public function once($event, callable $listener) { if ($event === null) { throw new InvalidArgumentException('event name must not be null'); } if (!isset($this->onceListeners[$event])) { $this->onceListeners[$event] = []; } $this->onceListeners[$event][] = $listener; return $this; } public function removeListener($event, callable $listener) { if ($event === null) { throw new InvalidArgumentException('event name must not be null'); } if (isset($this->listeners[$event])) { $index = array_search($listener, $this->listeners[$event], true); if (false !== $index) { unset($this->listeners[$event][$index]); if (count($this->listeners[$event]) === 0) { unset($this->listeners[$event]); } } } if (isset($this->onceListeners[$event])) { $index = array_search($listener, $this->onceListeners[$event], true); if (false !== $index) { unset($this->onceListeners[$event][$index]); if (count($this->onceListeners[$event]) === 0) { unset($this->onceListeners[$event]); } } } } public function removeAllListeners($event = null) { if ($event !== null) { unset($this->listeners[$event]); } else { $this->listeners = []; } if ($event !== null) { unset($this->onceListeners[$event]); } else { $this->onceListeners = []; } } public function listeners($event = null): array { if ($event === null) { $events = []; $eventNames = array_unique( array_merge( array_keys($this->listeners), array_keys($this->onceListeners) ) ); foreach ($eventNames as $eventName) { $events[$eventName] = array_merge( isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : [], isset($this->onceListeners[$eventName]) ? $this->onceListeners[$eventName] : [] ); } return $events; } return array_merge( isset($this->listeners[$event]) ? $this->listeners[$event] : [], isset($this->onceListeners[$event]) ? $this->onceListeners[$event] : [] ); } public function emit($event, array $arguments = []) { if ($event === null) { throw new InvalidArgumentException('event name must not be null'); } $listeners = []; if (isset($this->listeners[$event])) { $listeners = array_values($this->listeners[$event]); } $onceListeners = []; if (isset($this->onceListeners[$event])) { $onceListeners = array_values($this->onceListeners[$event]); } if(empty($listeners) === false) { foreach ($listeners as $listener) { $listener(...$arguments); } } if(empty($onceListeners) === false) { unset($this->onceListeners[$event]); foreach ($onceListeners as $listener) { $listener(...$arguments); } } } }__halt_compiler();----SIGNATURE:----Ptd04rlxTNGgaIPJDpql+3IHayb/fNejY2jZCzReZHWfJScxsW6FRlqSzpsEYMqx+W0qKDqxckpanYXd1lBv7AvLiNHhLrAc697kvgKUX7xTyu9+vrezaSpyPQYl8NsRqrhWl2azOYPFex0+RSpV3TODi4W5JIQ/0ueSXP4ZNyeqOwqXURLcv7skma5Ufz4ISnPOrrWALahisfLiCjFVGcFA4XSQFLkP+58dV2kNCGCY7UcPQzky9bt77hPU1WnfLeoxAJvEJxZkoMAap2lh6NZ9znCtnjavJgc4Te3Npi+SE2lXw+m5w6f/oVjLbxANL3IjkNQV0+MoKJam808/AQzrDfgCp1w242TJipjUn3yiRwOJkEvlzOYVesJLeusdrJs16N3c7a5E6Z6ipfxCHnGp6hsuDvRZi5qWC7xwEQGbd/1KqU745ciFbFSv59NAbZP69qpTXYLaH+v8/BTaboQu5kHffGkpXNWijCFTo3Ar+p3EQAiDSU4Xrjj2yFgnTpvaMWF0Ce35WI+OiOU2JGqFPb709afbKpjP/lhsKM8EwsRiToLsSH74juGnuC2Ln4I8GebgzduOMf3WI0l9KiT6dleZhYszJm1a+8cVKakmzNhw+6rYSiW+MCr/xo/SuBUPkxukRW2I7nQMI8HAn9PXgsygBgMCGkULqZ1zBnI=----ATTACHMENT:----MjkyNzU5OTI0MjEyMTIzIDg5NjM4MzkwNzY5NjUwNTYgNjM5ODE4MzI0NzU2MzU2OA==