diff --git a/ClientAbstracts.php b/ClientAbstracts.php index d10e7e7..1e7170c 100644 --- a/ClientAbstracts.php +++ b/ClientAbstracts.php @@ -5,6 +5,7 @@ namespace Kiri; use Closure; +use CurlHandle; defined('SPLIT_URL') or define('SPLIT_URL', '/(http[s]?:\/\/)?(([\w\-_]+\.)+\w+(:\d+)?)((\/[a-zA-Z0-9\-]+)+[\/]?(\?[a-zA-Z]+=.*)?)?/'); @@ -56,7 +57,7 @@ abstract class ClientAbstracts implements IClient /** - * @var resource|\Swoole\Coroutine\Http\Client|\Swoole\Client|\CurlHandle + * @var resource|\Swoole\Coroutine\Http\Client|\Swoole\Client|CurlHandle */ protected mixed $client; diff --git a/CoroutineClient.php b/CoroutineClient.php index d8e017b..dd87409 100644 --- a/CoroutineClient.php +++ b/CoroutineClient.php @@ -26,7 +26,7 @@ class CoroutineClient extends ClientAbstracts * @param $path * @param array|string $params * @return void - * @throws Exception + * @throws */ public function request(string $method, $path, array|string $params = []): void { @@ -58,7 +58,7 @@ class CoroutineClient extends ClientAbstracts /** * @param $url * @param array|string $data - * @throws Exception 使用swoole协程方式请求 + * @throws */ private function coroutine($url, array|string $data = []): void { @@ -81,7 +81,7 @@ class CoroutineClient extends ClientAbstracts * @param $path * @param $data * @return void - * @throws Exception + * @throws */ private function execute($path, $data): void { @@ -100,7 +100,7 @@ class CoroutineClient extends ClientAbstracts * @param $path * @param $data * @return void - * @throws Exception + * @throws */ private function retry($path, $data): void { diff --git a/CurlClient.php b/CurlClient.php index d4261cf..df9dc60 100644 --- a/CurlClient.php +++ b/CurlClient.php @@ -18,7 +18,7 @@ class CurlClient extends ClientAbstracts * @param $method * @param $path * @param array|string $params - * @throws Exception + * @throws */ public function request($method, $path, array|string $params = []): void { @@ -39,7 +39,7 @@ class CurlClient extends ClientAbstracts * @param $path * @param $method * @param $params - * @throws Exception + * @throws */ private function getCurlHandler($path, $method, $params): void { @@ -70,7 +70,7 @@ class CurlClient extends ClientAbstracts /** * @return void - * @throws Exception + * @throws */ private function curlHandlerSslSet(): void { @@ -90,7 +90,7 @@ class CurlClient extends ClientAbstracts * @param $resource * @param $path * @param $method - * @throws Exception + * @throws */ private function do($resource, $path, $method): void { @@ -143,7 +143,7 @@ class CurlClient extends ClientAbstracts /** - * @throws Exception + * @throws */ private function execute(): void { @@ -159,7 +159,7 @@ class CurlClient extends ClientAbstracts /** * @return void - * @throws Exception + * @throws */ private function retry(): void { @@ -186,7 +186,7 @@ class CurlClient extends ClientAbstracts /** * @param $output * @return void - * @throws Exception + * @throws */ private function explode($output): void { diff --git a/HttpParse.php b/HttpParse.php index 43a1e1d..003516c 100644 --- a/HttpParse.php +++ b/HttpParse.php @@ -11,99 +11,99 @@ use Exception; */ class HttpParse { - /** - * @param mixed ...$object - * @return string - */ - private static function getKey(...$object): string - { - $first = ''; - $tp = []; - foreach ($object as $value) { - if ($value === null) { - continue; - } - if (is_array($value)) { - $value = key($value); - } - if ($first === '') { - $first = $value; - } else { - $tp[] = $value; - } - } - $key = $first . '[' . implode('][', $tp) . ']'; - if (count($tp) < 1) { - $key = $first; - } - return $key; - } + /** + * @param mixed ...$object + * @return string + */ + private static function getKey(...$object): string + { + $first = ''; + $tp = []; + foreach ($object as $value) { + if ($value === null) { + continue; + } + if (is_array($value)) { + $value = key($value); + } + if ($first === '') { + $first = $value; + } else { + $tp[] = $value; + } + } + $key = $first . '[' . implode('][', $tp) . ']'; + if (count($tp) < 1) { + $key = $first; + } + return $key; + } - /** - * @param $data - * @return string - * @throws Exception - */ - public static function parse($data): string - { - $tmp = []; - if (is_string($data)) { - return $data; - } - foreach ($data as $key => $datum) { - if ($datum === null) { - continue; - } - $tmp[] = static::ifElse($key, $datum); - } - return implode('&', $tmp); - } + /** + * @param $data + * @return string + * @throws + */ + public static function parse($data): string + { + $tmp = []; + if (is_string($data)) { + return $data; + } + foreach ($data as $key => $datum) { + if ($datum === null) { + continue; + } + $tmp[] = static::ifElse($key, $datum); + } + return implode('&', $tmp); + } - /** - * @param $t - * @param $qt - * @return string - * @throws Exception - */ - private static function ifElse($t, $qt): string - { - if (is_numeric($qt)) { - return $t . '=' . $qt; - } - if (is_string($qt)) { - $string = $t . '=' . urlencode($qt); - } else { - $string = static::encode($t, $qt); - } - return $string; - } + /** + * @param $t + * @param $qt + * @return string + * @throws + */ + private static function ifElse($t, $qt): string + { + if (is_numeric($qt)) { + return $t . '=' . $qt; + } + if (is_string($qt)) { + $string = $t . '=' . urlencode($qt); + } else { + $string = static::encode($t, $qt); + } + return $string; + } - /** - * @param mixed ...$object - * @return string - * @throws Exception - */ - private static function encode(...$object): string - { - $ret = []; + /** + * @param mixed ...$object + * @return string + * @throws + */ + private static function encode(...$object): string + { + $ret = []; - $data = $object[count($object) - 1]; - $key = static::getKey(...$object); - foreach ($data as $s => $datum) { - if (is_array($datum)) { - $object[count($object) - 1] = $s; - $object[] = $datum; - $string = static::encode(...$object); - } else { - if (is_object($datum)) { - throw new Exception('Http body con\'t object.'); - } - $string = $key . '=' . urlencode($datum); - } - $ret[] = $string; - } - return implode('&', $ret); - } + $data = $object[count($object) - 1]; + $key = static::getKey(...$object); + foreach ($data as $s => $datum) { + if (is_array($datum)) { + $object[count($object) - 1] = $s; + $object[] = $datum; + $string = static::encode(...$object); + } else { + if (is_object($datum)) { + throw new Exception('Http body con\'t object.'); + } + $string = $key . '=' . urlencode($datum); + } + $ret[] = $string; + } + return implode('&', $ret); + } } diff --git a/TcpClient.php b/TcpClient.php index 11e5c1e..0970632 100644 --- a/TcpClient.php +++ b/TcpClient.php @@ -22,7 +22,7 @@ class TcpClient * @param string $host * @param int $port * @param int $socket - * @throws Exception + * @throws */ public function __construct(readonly public string $host, readonly public int $port, readonly public int $socket = SWOOLE_SOCK_TCP) { @@ -32,7 +32,7 @@ class TcpClient /** * @return void - * @throws Exception + * @throws */ public function reconnect(): void {