* * 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:----jYjsIg4UGXsT3PC0E1Gejbd9s42Q6frZB6eL7NTs//zeOImIyK/2dtptuiiRM240wmwfvIHcEczd1MUvdWLrEYaCL9Xf3UX8AqZDabbjXqr0h94szi664SiCE73H+iEX+5EBN9pwV3PoCMSd52V6dVkHVQPqVVn9cJqrJGgBL30R/aRqNflzQ+1BoqY+L//B/w4b8rAmptRXYXBqv9qhtkIC1Jfqp2U+sKFkipZGSICLqIsZ+4nRaLrnfI6YcYRgSHQ1Yl1Cby7FJrC89i6w/2cl1qKw7/gFATknYBn2Kj58+sTpojFhp9+ZOPWvPM1Ms/kbmbOkmJx1sCuq7T/qxBDIIJLXhRntSNPHCz2DzD9FF+aHZCd5BVc6DJO22o/sD2rG8j6LgeEWAz/UZ4zwzshDZjI4VitHwSgUbD3oyPztUPswqg2z0vivzAmvBOCkSDTBpB3pemyg/py37mKhmFN9r4nWR8iuoQ/ckCeuGAQDMoEllw5KNJ/iX2iv475l2HR/yzwD6Pj/k4xvoXgjmMZdXBC+EY2MrD9VOzFyvHPgvn3gZWN770sWEe2cnu47bqkRQ6L+Z9iIRaOmWU3dVjH2Avp89CvfBpwop4cVryDB974zT1Uh9mGI3AWsqQ+rzkjxyUjJ4Ee+Tr5JPuevCxy4QAgRMOksJjQIhh2kBDM=----ATTACHMENT:----OTMzNjcxODkwNDAwMTM1MiA5Mjk5MDA4NTgxODQ4ODAyIDkzNzczOTM3MzAyOTQ4NTA=