* * 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:----HJ44mdCPRTOIopLX12KN9PyRdCYCuQwFp1j9laOh0fZkhsAr6JopNFiTu11P4C3TVakM/ltL6j4y0akEZCKNdAKZpDsLkppq0M3aOg3j3c0V0lQhN7NuCKArnepN81+/Mg77l+hoBDTbgCl2ulGIq6Bfhb/m0zafFrPUlP7EeVhNxe1tNqqUbnBqmXZU4JwJSXD7WSJZJwchsYbWDE+6Ms/NlUCmTAjs952FF7aSg/JeBknT1+E5hpamf/2k25gwu7udG2Nx2bdgBgcCbCg1ZWsU6NRa9/P3dQTjedYBiwqmCo69v9kDIqNFFYxZlq2hWjWDlYRCZJDkvejLmjR2CGRn/j50VlYvPSSwJeDnqvtC5btw5ej3Fdr0rci/cD5R7RlamPvPcb/0+u3Ohn9xibB/n1UmJb+ccABizdezNcIcKQoKeOurBMsNVzRmiqPO5eyyfO7+KwX9IneLpqaAVgwWMkUiECSvPMNlxnnpNJf7cSM9JRv1bYOa37LQaK4dkX0ew/e2+vvwLWw1MXhcngWzuleOuH+bNm3ulmkjpMZL0pBjhzXfWCtNim8NhLWgjYYH9MOVX3GRLQxAUOM6+sM4aCmal3ezg7TvBVwTJUM+WNBzlVKaNJ/TANfSTP9SWIjpdkSj8vGEO5CLAWIhoW+Z+3E6KZINjb9BTLmcJQ0=----ATTACHMENT:----NTQ0MjYzMjc2Mjc3MzAzMyAxOTQxMjkzNDU3Njk5OTU0IDU4NzAxMzA1ODgzNTY2ODQ=