From b558a237fc6f48ea697203a1cef49f9c2aee2638 Mon Sep 17 00:00:00 2001 From: zhuwene <374848541@qq.com> Date: Mon, 28 Feb 2022 15:34:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BE=E7=BD=AE=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E5=8F=82=E6=95=B0=E3=80=81=E5=92=8C=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E6=96=AD=E5=BC=80=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Client.php | 9 ++++++++- src/ClientFactory.php | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index 39cfaa3..f9db70a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -29,7 +29,7 @@ class Client */ protected $client; - public function __construct(UriInterface $uri) + public function __construct(UriInterface $uri, array $options = []) { $this->uri = $uri; $host = $uri->getHost(); @@ -42,6 +42,8 @@ public function __construct(UriInterface $uri) $this->client = new Coroutine\Http\Client($host, $port, $ssl); + $this->client->set($options); + parse_str($this->uri->getQuery(), $query); $query = http_build_query($query); @@ -90,4 +92,9 @@ public function close(): bool { return $this->client->close(); } + + public function isConnected(): bool + { + return $this->client->connected; + } } diff --git a/src/ClientFactory.php b/src/ClientFactory.php index 02271ac..5345894 100644 --- a/src/ClientFactory.php +++ b/src/ClientFactory.php @@ -16,12 +16,12 @@ class ClientFactory { - public function create(string $uri, bool $autoClose = true): Client + public function create(string $uri, bool $autoClose = true, array $options = []): Client { if (! Str::startsWith($uri, ['ws://', 'wss://'])) { $uri = 'ws://' . $uri; } - $client = make(Client::class, ['uri' => new Uri($uri)]); + $client = make(Client::class, ['uri' => new Uri($uri), 'options' => $options]); if ($autoClose) { defer(function () use ($client) { $client->close();