* * 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:----fz814MnTk0A57o3AQUGF2CRYWYnHKoDidx5i0NVYfB/trziSLQhz74yrd8dztw7P5Gl72pnpmgp3uaW5BPJ8KYorijIep48Z91/LX4ej6LCbpHIiCrXzIUmCb+NDaWdIB456sq2T0/fN6KsRqly8t2hL+4fPiBAwF1Dc8rSc6tHKjYu3iBuvCp2MR8UzyIViKiWRhu3NlrkMN/PhLmvXyCS7Mr/Y3dwWCqX/+wKZprPxiHJ3+aLWMmh+DsH9fL4jwM9Hne/0p4G4eSMldraYi9Te9yIo/fzBL0/KqV8PC52n9bA44Epz2kkmg5ao7xa9AT6u5tPmDwgMN3Z0ijUgMgSRNoyOtbH/5b9cZBAIqJl8FPTRTFbC6vf2rVEkTCLkG8nNfFBgqlpYsH7F+w1YLsdERW3A1w5iB2qxOh95ZzFnk5iWAKmcGo9gl9Pczz4tN0BmC8xPJcYmHLHQrPUqYbRLWvsYNv1mNjtX4ocliC7uF4KxGf8enTqPVP2CtShzy3qAReShSlfHOvy0YSsobZW3ciDhHDS8B5KxWS0U6ZJMkE6edje1aFjZBsjEaUDveubAedwdFGbQAH2RSCmIVSJ7d1ypEJLE4Fi45mkxkWGG5TwEg5P0gjNo+ONf9tea7sUtWSxJkwqxSHX53C5WtFjItpU7jjj/RR8NV/T8w14=----ATTACHMENT:----OTcwMjIyNDc3MjQ1MzkzNiA1Njk1NjM2Mjc3NDA1MjA4IDM0Njg4NTc5ODQ2MzIzNDE=