71 lines
1.3 KiB
PHP
71 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Kiri;
|
|
|
|
use Exception;
|
|
use Swoole\Coroutine;
|
|
|
|
|
|
/**
|
|
* @mixin CoroutineClient|CurlClient
|
|
*/
|
|
class Client
|
|
{
|
|
|
|
|
|
private CoroutineClient|CurlClient $abstracts;
|
|
|
|
|
|
/**
|
|
* @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) {
|
|
$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);
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @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.');
|
|
}
|
|
|
|
}
|