From 82f046f38bc04c2d2965b1eb75d46df9096be919 Mon Sep 17 00:00:00 2001 From: Administrator Date: Sat, 11 Dec 2021 17:31:21 +0800 Subject: [PATCH] 1 --- src/AsyncClient.php | 30 +++--------------------------- src/CoroutineClient.php | 29 ++--------------------------- src/TSwooleClient.php | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 54 deletions(-) create mode 100644 src/TSwooleClient.php diff --git a/src/AsyncClient.php b/src/AsyncClient.php index cede419..a175c78 100644 --- a/src/AsyncClient.php +++ b/src/AsyncClient.php @@ -11,7 +11,6 @@ namespace Http\Client; use Exception; use Http\Message\Stream; -use JetBrains\PhpStorm\Pure; use Kiri\Abstracts\Logger; use Kiri\Kiri; use Swoole\Client as SwowClient; @@ -23,6 +22,9 @@ use Swoole\Client as SwowClient; class AsyncClient extends ClientAbstracts { + + use TSwooleClient; + /** * @param string $method * @param $path @@ -147,30 +149,4 @@ class AsyncClient extends ClientAbstracts { $this->client->close(); } - - /** - * @return array - */ - #[Pure] private function settings(): array - { - $sslCert = $this->getSslCertFile(); - $sslKey = $this->getSslKeyFile(); - $sslCa = $this->getCa(); - - $params = []; - if ($this->getConnectTimeout() > 0) { - $params['timeout'] = $this->getConnectTimeout(); - } - if (empty($sslCert) || empty($sslKey) || empty($sslCa)) { - return $params; - } - - $params['ssl_host_name'] = $this->getHost(); - $params['ssl_cert_file'] = $this->getSslCertFile(); - $params['ssl_key_file'] = $this->getSslKeyFile(); - $params['ssl_verify_peer'] = TRUE; - $params['ssl_cafile'] = $sslCa; - - return $params; - } } diff --git a/src/CoroutineClient.php b/src/CoroutineClient.php index 8ae0e0a..b013fb6 100644 --- a/src/CoroutineClient.php +++ b/src/CoroutineClient.php @@ -22,6 +22,8 @@ use Swoole\Coroutine\Http\Client as SwowClient; class CoroutineClient extends ClientAbstracts { + use TSwooleClient; + /** * @param string $method * @param $path @@ -117,7 +119,6 @@ class CoroutineClient extends ClientAbstracts return $path; } - /** * */ @@ -125,30 +126,4 @@ class CoroutineClient extends ClientAbstracts { $this->client->close(); } - - /** - * @return array - */ - #[Pure] private function settings(): array - { - $sslCert = $this->getSslCertFile(); - $sslKey = $this->getSslKeyFile(); - $sslCa = $this->getCa(); - - $params = []; - if ($this->getConnectTimeout() > 0) { - $params['timeout'] = $this->getConnectTimeout(); - } - if (empty($sslCert) || empty($sslKey) || empty($sslCa)) { - return $params; - } - - $params['ssl_host_name'] = $this->getHost(); - $params['ssl_cert_file'] = $this->getSslCertFile(); - $params['ssl_key_file'] = $this->getSslKeyFile(); - $params['ssl_verify_peer'] = true; - $params['ssl_cafile'] = $sslCa; - - return $params; - } } diff --git a/src/TSwooleClient.php b/src/TSwooleClient.php new file mode 100644 index 0000000..8539901 --- /dev/null +++ b/src/TSwooleClient.php @@ -0,0 +1,38 @@ +getSslCertFile(); + $sslKey = $this->getSslKeyFile(); + $sslCa = $this->getCa(); + + $params = []; + if ($this->getConnectTimeout() > 0) { + $params['timeout'] = $this->getConnectTimeout(); + } + if (empty($sslCert) || empty($sslKey) || empty($sslCa)) { + return $params; + } + + $params['ssl_host_name'] = $this->getHost(); + $params['ssl_cert_file'] = $this->getSslCertFile(); + $params['ssl_key_file'] = $this->getSslKeyFile(); + $params['ssl_verify_peer'] = TRUE; + $params['ssl_cafile'] = $sslCa; + + return $params; + } + +} \ No newline at end of file