Compare commits
4 Commits
v2.11
...
d1adc532e1
| Author | SHA1 | Date | |
|---|---|---|---|
| d1adc532e1 | |||
| ec22ac39a3 | |||
| b96bd159d3 | |||
| c31211a6fa |
+29
-6
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Kiri;
|
namespace Kiri;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Swoole\Coroutine;
|
use Swoole\Coroutine;
|
||||||
|
|
||||||
|
|
||||||
@@ -15,11 +16,11 @@ class Client
|
|||||||
private CoroutineClient|CurlClient $abstracts;
|
private CoroutineClient|CurlClient $abstracts;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $host
|
* @param string $host
|
||||||
* @param int $port
|
* @param int $port
|
||||||
* @param bool $isSsl
|
* @param bool $isSsl
|
||||||
*/
|
*/
|
||||||
public function __construct(string $host, int $port, bool $isSsl = false)
|
public function __construct(string $host, int $port, bool $isSsl = false)
|
||||||
{
|
{
|
||||||
if (class_exists(Coroutine::class) && Coroutine::getCid() > -1) {
|
if (class_exists(Coroutine::class) && Coroutine::getCid() > -1) {
|
||||||
@@ -32,7 +33,7 @@ class Client
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $arguments
|
* @param array $arguments
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function __call(string $name, array $arguments)
|
public function __call(string $name, array $arguments)
|
||||||
@@ -40,4 +41,26 @@ class Client
|
|||||||
return $this->abstracts->{$name}(...$arguments);
|
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, $getter)) {
|
||||||
|
return $this->$getter();
|
||||||
|
} else if (method_exists($this, $name)) {
|
||||||
|
return $this->$name();
|
||||||
|
} else if (property_exists($this, $name)) {
|
||||||
|
return $this->$name;
|
||||||
|
} else {
|
||||||
|
throw new Exception('Property|Method "' . $name . '" does not exist.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-101
@@ -25,117 +25,35 @@ abstract class ClientAbstracts implements IClient
|
|||||||
const string HEAD = 'head';
|
const string HEAD = 'head';
|
||||||
const string PUT = 'put';
|
const string PUT = 'put';
|
||||||
|
|
||||||
public string $host = '' {
|
public string $host = '';
|
||||||
get {
|
protected array $header = [];
|
||||||
return $this->host;
|
protected int $timeout = 0;
|
||||||
}
|
protected string $method = 'get';
|
||||||
}
|
protected bool $isSSL = FALSE;
|
||||||
protected array $header = [] {
|
protected string $agent = '';
|
||||||
&get {
|
public string $ssl_cert_file = '';
|
||||||
return $this->header;
|
public string $ssl_key_file = '';
|
||||||
}
|
public string $ca = '';
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private int $port = 80;
|
private int $port = 80;
|
||||||
protected int $num = 0;
|
protected int $num = 0;
|
||||||
private ?array $_responseHeader = [] {
|
private ?array $_responseHeader = [];
|
||||||
&get {
|
public int $statusCode = 200;
|
||||||
return $this->_responseHeader;
|
protected int $retryNum = 0;
|
||||||
}
|
protected int $retryTimeout = 0;
|
||||||
}
|
private bool $verifyPeer = TRUE;
|
||||||
public int $statusCode = 200 {
|
public string $proxyHost = '';
|
||||||
get {
|
public int $proxyPort = 0;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string|null
|
* @var string|null
|
||||||
*/
|
*/
|
||||||
public ?string $body {
|
public ?string $body;
|
||||||
get {
|
|
||||||
return $this->body;
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
$this->body = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected string|array|null $_data = NULL {
|
protected string|array|null $_data = NULL;
|
||||||
get {
|
|
||||||
return $this->_data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int $connect_timeout = 1 {
|
public int $connect_timeout = 1;
|
||||||
get {
|
|
||||||
return $this->connect_timeout;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -186,7 +186,7 @@ class CurlClient extends ClientAbstracts
|
|||||||
*/
|
*/
|
||||||
public function close(): void
|
public function close(): void
|
||||||
{
|
{
|
||||||
if (PHP_VERSION < 80000) {
|
if (PHP_VERSION < '8.0') {
|
||||||
curl_close($this->client);
|
curl_close($this->client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user