Skip to content

Commit

Permalink
Merge pull request #21 from tioncico/master
Browse files Browse the repository at this point in the history
完善setUrl 的传值,以及修复getCLient之后不能setUrl的问题
  • Loading branch information
kiss291323003 authored Dec 11, 2019
2 parents 99fbdce + 9131ada commit 2d363b1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@ public function setQuery(?array $data = 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处理
Expand All @@ -133,6 +137,7 @@ public function setUrl(string $url): HttpClient
return $this;
}


/**
* 强制开启SSL
* @param bool $enableSSL
Expand Down Expand Up @@ -338,9 +343,15 @@ public function setClientSettings(array $settings, $isMerge = true): HttpClient
return $this;
}


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();
Expand Down

0 comments on commit 2d363b1

Please sign in to comment.