Compare commits

...

7 Commits

Author SHA1 Message Date
as2252258 eb42c8e0a2 eee 2026-07-03 16:15:52 +08:00
as2252258 10de0d5e08 eee 2026-07-03 16:10:28 +08:00
as2252258 d1adc532e1 eee 2026-07-03 16:08:07 +08:00
as2252258 ec22ac39a3 eee 2026-07-03 16:07:27 +08:00
as2252258 b96bd159d3 eee 2026-07-03 15:59:49 +08:00
as2252258 c31211a6fa eee 2026-07-03 15:53:55 +08:00
as2252258 45d8931267 eee 2026-07-03 15:06:12 +08:00
3 changed files with 55 additions and 108 deletions
+33 -6
View File
@@ -2,6 +2,7 @@
namespace Kiri;
use Exception;
use Swoole\Coroutine;
@@ -15,11 +16,11 @@ class Client
private CoroutineClient|CurlClient $abstracts;
/**
* @param string $host
* @param int $port
* @param bool $isSsl
*/
/**
* @param string $host
* @param int $port
* @param bool $isSsl
*/
public function __construct(string $host, int $port, bool $isSsl = false)
{
if (class_exists(Coroutine::class) && Coroutine::getCid() > -1) {
@@ -32,7 +33,7 @@ class Client
/**
* @param string $name
* @param array $arguments
* @param array $arguments
* @return mixed
*/
public function __call(string $name, array $arguments)
@@ -40,4 +41,30 @@ class Client
return $this->abstracts->{$name}(...$arguments);
}
/**
* @param string $name
* @return mixed
* @throws Exception
*/
public function __get(string $name)
{
// TODO: Implement __get() method.
$getter = 'get' . ucfirst($name);
if (method_exists($this->abstracts, $getter)) {
return $this->abstracts->$getter();
}
if (method_exists($this->abstracts, $name)) {
return $this->abstracts->$name();
}
if (property_exists($this->abstracts, $name)) {
return $this->abstracts->$name;
}
throw new Exception('Property|Method "' . $name . '" does not exist.');
}
}
+19 -101
View File
@@ -25,117 +25,35 @@ abstract class ClientAbstracts implements IClient
const string HEAD = 'head';
const string PUT = 'put';
public string $host = '' {
get {
return $this->host;
}
}
protected array $header = [] {
&get {
return $this->header;
}
}
protected int $timeout = 0 {
get {
return $this->timeout;
}
}
protected string $method = 'get' {
get {
return $this->method;
}
}
protected bool $isSSL = FALSE {
get {
return $this->isSSL;
}
}
protected string $agent = '' {
get {
return $this->agent;
}
}
public string $ssl_cert_file = '' {
get {
return $this->ssl_cert_file;
}
}
public string $ssl_key_file = '' {
get {
return $this->ssl_key_file;
}
}
public string $ca = '' {
get {
return $this->ca;
}
}
public string $host = '';
protected array $header = [];
protected int $timeout = 0;
protected string $method = 'get';
protected bool $isSSL = FALSE;
protected string $agent = '';
public string $ssl_cert_file = '';
public string $ssl_key_file = '';
public string $ca = '';
private int $port = 80;
protected int $num = 0;
private ?array $_responseHeader = [] {
&get {
return $this->_responseHeader;
}
}
public int $statusCode = 200 {
get {
return $this->statusCode;
}
set {
$this->statusCode = $value;
}
}
protected int $retryNum = 0 {
get {
return $this->retryNum;
}
}
protected int $retryTimeout = 0 {
get {
return $this->retryTimeout;
}
}
private bool $verifyPeer = TRUE {
get {
return $this->verifyPeer;
}
}
public string $proxyHost = '' {
get {
return $this->proxyHost;
}
}
public int $proxyPort = 0 {
get {
return $this->proxyPort;
}
}
private ?array $_responseHeader = [];
public int $statusCode = 200;
protected int $retryNum = 0;
protected int $retryTimeout = 0;
private bool $verifyPeer = TRUE;
public string $proxyHost = '';
public int $proxyPort = 0;
/**
* @var string|null
*/
public ?string $body {
get {
return $this->body;
}
set {
$this->body = $value;
}
}
public ?string $body;
protected string|array|null $_data = NULL {
get {
return $this->_data;
}
}
protected string|array|null $_data = NULL;
public int $connect_timeout = 1 {
get {
return $this->connect_timeout;
}
}
public int $connect_timeout = 1;
/**
+3 -1
View File
@@ -186,7 +186,9 @@ class CurlClient extends ClientAbstracts
*/
public function close(): void
{
curl_close($this->client);
if (PHP_VERSION < '8.0') {
curl_close($this->client);
}
}