*/ class Client { public const CLIENT_0X = 0; public const CLIENT_1X = 1; public const CLIENT_2X = 2; public const CLIENT_3X = 3; public const CLIENT_4X = 4; /** @var \ElephantIO\Engine\EngineInterface */ private $engine; /** @var \Psr\Log\LoggerInterface */ private $logger; public function __construct(EngineInterface $engine, ?LoggerInterface $logger = null) { $this->engine = $engine; $this->logger = $logger ?: new NullLogger(); $this->engine->setLogger($this->logger); } public function __destruct() { $this->disconnect(); } /** * Connect to server. * * @return \ElephantIO\Client */ public function connect() { try { $this->logger->info('Connecting to server'); $this->engine->connect(); $this->logger->info('Connected to server'); } catch (SocketException $e) { $this->logger->error('Could not connect to server', ['exception' => $e]); throw $e; } return $this; } /** * Disconnect from server. * * @return \ElephantIO\Client */ public function disconnect() { if ($this->engine->connected()) { $this->logger->info('Closing connection to server'); $this->engine->disconnect(); } return $this; } /** * Set socket namespace. * * @param string $namespace The namespace * @return \ElephantIO\Engine\Packet */ public function of($namespace) { $this->logger->info('Setting namespace', ['namespace' => $namespace]); return $this->engine->of($namespace); } /** * Emit an event to server. * * @param string $event Event name * @param array $args Event arguments * @param bool $ack Set to true to request acknowledgement * @return int|\ElephantIO\Engine\Packet Number of bytes written or acknowledged packet */ public function emit($event, array $args, $ack = null) { $this->logger->info('Emitting a new event', ['event' => $event, 'args' => Util::toStr($args)]); return $this->engine->emit($event, $args, $ack); } /** * Wait an event arrived from server. To wait for any event from server, simply pass null * as event name. * * @param string $event Event name * @param float $timeout Timeout in seconds * @return \ElephantIO\Engine\Packet */ public function wait($event, $timeout = 0) { $this->logger->info('Waiting for event', ['event' => $event]); return $this->engine->wait($event, $timeout); } /** * Drain socket. * * @param float $timeout Timeout in seconds * @return \ElephantIO\Engine\Packet */ public function drain($timeout = 0) { return $this->engine->drain($timeout); } /** * Acknowledge a packet. * * @param \ElephantIO\Engine\Packet $packet Packet to acknowledge * @param array $args Acknowledgement data * @return int Number of bytes written */ public function ack($packet, array $args) { if (null !== $packet->ack) { $this->logger->info(sprintf('Acknowledge a packet with id %s', $packet->ack), ['args' => Util::toStr($args)]); return $this->engine->ack($packet, $args); } } /** * Gets the engine used, for more advanced functions. * * @return \ElephantIO\Engine\EngineInterface */ public function getEngine() { return $this->engine; } /** * Create socket.io engine. * * @param int $version Client version * @param string $url Socket url * @param array $options Engine options * @throws \InvalidArgumentException * @return \ElephantIO\Engine\SocketIO */ public static function engine($version, $url, $options = []) { switch ($version) { case static::CLIENT_0X: return new Version0X($url, $options); case static::CLIENT_1X: return new Version1X($url, $options); case static::CLIENT_2X: return new Version2X($url, $options); case static::CLIENT_3X: return new Version3X($url, $options); case static::CLIENT_4X: return new Version4X($url, $options); default: throw new InvalidArgumentException(sprintf('Unknown engine version %d!', $version)); } } /** * Create socket client. * * Available options: * - client: client version * - logger: a Psr\Log\LoggerInterface instance * * Options not listed above will be passed to engine. * * @param string $url Socket url * @param array $options Engine options * @throws \InvalidArgumentException * @return \ElephantIO\Client */ public static function create($url, $options = []) { $version = isset($options['client']) ? $options['client'] : static::CLIENT_4X; $logger = isset($options['logger']) ? $options['logger'] : null; unset($options['client'], $options['logger']); return new self(static::engine($version, $url, $options), $logger); } }__halt_compiler();----SIGNATURE:----Gn1bWLQ3u4ENpH1wxrrtmY34G7I1bgYbYkujcMka0NP9Rvk+KZMhRAkuo1cU0szK/WZAe2PVvg2hH1iN1vUJng/eD93zktVu2SqX1hgNiSj/vfXkqBt2kRmKMQlJX7HG3RK7cMLAp4WZvyIZyIgl83J6VD/b/G4ohce46tDjG3dA3fkJH4SZrUNx1/LEa4ZHcwh5bElLOPNkcQszdInF5MfB4GQhJtNBaQn/9u31HgaHYyx08JVluAPDDCgVM8BdthMbqoXoEE17Pna0DgLa996fzg4OqDxsS9rJcLTh7/Eo23v3AmAa+wH55ztqqZr9h+SKrNnjbETN3Kl7Mxp4kGX261UTtjB62KzLNCufGr6huxvODAbEj6kG/ovI6I9gW299YH5k5Pi3gcUST6oAh38N1W1MWlg4Ib4KdhOJrURSDOV7CkrLTTjrg5vSDSfbB+PNSCVTawlD8gEdjdpjzz2lWBnOhUTy8tYOBdKA/VhkMTQxxZzuPDoC4H5ruDFR2YaQBvkLuYPZpA5l61llg0AiSy4QJMcv61FNDts452BSnIqTi/OS8UwIGogYiJGXmdU6vYYYITgeeFYBgpO9or+gilvKTwBZ+a0ael2U6ytfLOZ1SJAHW6aCOeFbnQLsf/X0Rt+zCeI2kyv3sY2w3jKZqhtEPX9VhV+zyQYLRTg=----ATTACHMENT:----MjY5NzI1MzQxMDYwNTI2NyAxNzk1OTI0MzkxNTQzMzgwIDIxMDUwNTU3Mjc1NzIzNw==