* * 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:----kMM3fwvouMSTmijhft9FMVMbUShCs3DoDjWEQtTLeUCQAV2qg5QX5V8an7DN6zOgVCskLDLfO0HT9NxcZEhM8EhsqNOz88uUWKVeoo3GhsBO7val/tfK2YjvgWG/gYNzk91qSxbxorxPwydPiUBH5SI0qsJT0Fjs/C2R23RE84UUu/KZrIBGsPomYCXckSNkGvVkMPnzhjEryOOCq+eHTx4XVhEbOr1pT0jlO1UslAiidCx6ox/E7hnzvoZdP7AF+oo44i4Q7dKH8OaQB372Abenv/WSjY/GCVW4lSA2VvRV2F1d/CGXF7QNM5zCyjbWERPfTW8KwTEF4PXQApyI6tN4OepTc44V9PWYmsCyrUvAZBFaGaE1YDVXIDks+XN4C05AkE9PBq0ZwggkmssPyp9pIUVMug9ampFIOmul6+ReSdoJFaVMeP89CHkAYvmynm9age4MZrSUqfJJifdSooa7BahYHiGTSJXU0MxwFVBiI+hM1oq/z8TsJ98eRpJrZ24tTZYuEQHNaAs7rKpS8qlTK+OwzyhElxxMYe5v7OHg0sLuWLidqLzcUOTGsCMYixHMQl8f3xjC+cRmtmB+tKKv+6aCyAgvVOFwQ5/rd8CYtQWAGTgq8LTF6nUmVqrhmdScE3KqCEq5uuHjIn+uguXkdIyXRA5ITdY5L7vxWNI=----ATTACHMENT:----MTMzMTIzMTI4MDU3MDc0MiA4NTE1MTI2NjAzMTM1NDI4IDMyNjk4NjkwNjkxMTY3OTY=