Files
kiri-client/Client.php
T

49 lines
962 B
PHP
Raw Normal View History

2022-01-09 13:54:34 +08:00
<?php
2022-01-10 11:39:56 +08:00
namespace Kiri;
2022-01-09 13:54:34 +08:00
2022-09-08 14:07:22 +08:00
use Swoole\Coroutine;
2022-01-09 13:54:34 +08:00
/**
* @mixin CoroutineClient|CurlClient
*/
class Client
{
2022-09-08 14:07:22 +08:00
private CoroutineClient|CurlClient $abstracts;
2022-01-09 13:54:34 +08:00
2023-08-18 17:33:06 +08:00
/**
* @param string $host
* @param int $port
* @param bool $isSsl
* @param bool $useCurl
*/
public function __construct(string $host, int $port, bool $isSsl = false, bool $useCurl = false)
2022-01-09 13:54:34 +08:00
{
2023-08-18 17:33:06 +08:00
if ($useCurl) {
$this->abstracts = new CurlClient($host, $port, $isSsl);
return;
}
2022-09-08 14:07:22 +08:00
if (class_exists(Coroutine::class) && Coroutine::getCid() > -1) {
2022-01-09 13:54:34 +08:00
$this->abstracts = new CoroutineClient($host, $port, $isSsl);
} else {
$this->abstracts = new CurlClient($host, $port, $isSsl);
}
}
/**
* @param string $name
* @param array $arguments
* @return mixed
*/
public function __call(string $name, array $arguments)
{
return $this->abstracts->{$name}(...$arguments);
}
}