* * 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:----bU9OpTlciMgR9As9KCkevPFnTIKnA84V6Fz6s94J62kDXrCV0bvj2oXmzfNC7uHuhGDwTp40FfHsTIVGCEKltifQqA34khfsjoexg/dqLdGYy8IvKOj9ZfjPb3S2EXkOrMQqImQBZsjSLXSCRr/mRKAiWLhQg/Pp+xGTSOJ72IDh5DceSh+VmHwY0/Zw4/egK0XOX1aOpC8F59gJIbrl30/O+ykh21Na63CJAm14GVFVNO538zj3VVuNRRvA4+SYIsuods39/Skzk5IuFJCGewkj8U217TNiL2tHmPW1yXgZSC4BGJjsAcyHQQ0I+Zgu45XnJRruYoR2hV4L2CtpHvy92mGOIfo7+HGb8k69nA4iVcLy4qElTbi7HkZyj+UsWDRlgjyrxaQE0kxawOOPlOmRZu1A1C2Dw2NY6qpjAIgpnmTlIv831L4EQ3mdzpu2uvkU3rxSUYbif911l6ld22CSmCH+za7IhrVyVNFeDOT6PfB5gA0Ow/V5igTh6uMuN6j+GqW7qWHpUuWUNgnHZv+OPufeQqISv8VKI2rs4NAdq3eayBGHNanyZHrpwJPagVSlSrz29AZL+T/cgtyeE6Fp9VRS/uZT5FX8zG9qbNSDftdl6HVZe024sclv11xqzEzECK9UtQiPYkrRr8YdwNnkMruyRUMdWVDvIah9TDc=----ATTACHMENT:----NzUzNzk2NjE1MDIzOTcxNyA3NzM5NDIyMzA0MjE1NjU0IDk2OTQ4NTgyMjgyNDY3ODk=