From a3291f60433188b70aeda447dc5130dea9f12e7f Mon Sep 17 00:00:00 2001 From: tioncico <1067197739@qq.com> Date: Wed, 11 Dec 2019 11:07:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AE=8C=E5=96=84setUrl=20=E7=9A=84?= =?UTF-8?q?=E4=BC=A0=E5=80=BC,=E4=BB=A5=E5=8F=8A=E4=BF=AE=E5=A4=8DgetCLien?= =?UTF-8?q?t=E4=B9=8B=E5=90=8E=E4=B8=8D=E8=83=BDsetUrl=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/HttpClient.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/HttpClient.php b/src/HttpClient.php index 6721089..3f83c55 100644 --- a/src/HttpClient.php +++ b/src/HttpClient.php @@ -100,8 +100,12 @@ public function __construct(?string $url = null) * @return HttpClient * @throws InvalidUrl */ - public function setUrl(string $url): HttpClient + public function setUrl($url): HttpClient { + if ($url instanceof Url){ + $this->url = $url; + return $this; + } $info = parse_url($url); if (empty($info['scheme'])) { $info = parse_url('//' . $url); // 防止无scheme导致的host解析异常 默认作为http处理 @@ -321,12 +325,18 @@ public function setClientSettings(array $settings, $isMerge = true): HttpClient public function getClient(): Client { if ($this->httpClient instanceof Client) { + $url = $this->parserUrlInfo(); + $this->httpClient->host = $url->getHost(); + $this->httpClient->port = $url->getPort(); + $this->httpClient->ssl = $url->getIsSsl(); + $this->httpClient->set($this->clientSetting); return $this->httpClient; } $url = $this->parserUrlInfo(); $this->httpClient = new Client($url->getHost(), $url->getPort(), $url->getIsSsl()); $this->httpClient->set($this->clientSetting); return $this->getClient(); + } public function setMethod(string $method):HttpClient From 9131adaeaedb43bd7b9d71a1fa5dca0bbe244bf9 Mon Sep 17 00:00:00 2001 From: tioncico <1067197739@qq.com> Date: Wed, 11 Dec 2019 11:25:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AE=8C=E5=96=84setUrl=20=E7=9A=84?= =?UTF-8?q?=E4=BC=A0=E5=80=BC,=E4=BB=A5=E5=8F=8A=E4=BF=AE=E5=A4=8DgetCLien?= =?UTF-8?q?t=E4=B9=8B=E5=90=8E=E4=B8=8D=E8=83=BDsetUrl=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/HttpClient.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/HttpClient.php b/src/HttpClient.php index 232099b..9e024e6 100644 --- a/src/HttpClient.php +++ b/src/HttpClient.php @@ -137,6 +137,7 @@ public function setUrl($url): HttpClient return $this; } + /** * 强制开启SSL * @param bool $enableSSL @@ -342,6 +343,7 @@ public function setClientSettings(array $settings, $isMerge = true): HttpClient return $this; } + public function getClient(): Client { if ($this->httpClient instanceof Client) { @@ -356,7 +358,6 @@ public function getClient(): Client $this->httpClient = new Client($url->getHost(), $url->getPort(), $url->getIsSsl()); $this->httpClient->set($this->clientSetting); return $this->getClient(); - } public function setMethod(string $method):HttpClient