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
|
|
|
|
2026-07-03 16:07:27 +08:00
|
|
|
use Exception;
|
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
|
|
|
|
|
|
|
|
|
2026-07-03 16:07:27 +08:00
|
|
|
/**
|
|
|
|
|
* @param string $host
|
|
|
|
|
* @param int $port
|
|
|
|
|
* @param bool $isSsl
|
|
|
|
|
*/
|
2023-08-18 19:50:43 +08:00
|
|
|
public function __construct(string $host, int $port, bool $isSsl = false)
|
2022-01-09 13:54:34 +08:00
|
|
|
{
|
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
|
2026-07-03 16:07:27 +08:00
|
|
|
* @param array $arguments
|
2022-01-09 13:54:34 +08:00
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function __call(string $name, array $arguments)
|
|
|
|
|
{
|
|
|
|
|
return $this->abstracts->{$name}(...$arguments);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-03 16:07:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @return mixed
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function __get(string $name)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement __get() method.
|
2026-07-03 16:08:07 +08:00
|
|
|
$getter = 'get' . ucfirst($name);
|
|
|
|
|
if (method_exists($this, $getter)) {
|
|
|
|
|
return $this->$getter();
|
|
|
|
|
} else if (method_exists($this, $name)) {
|
2026-07-03 16:07:27 +08:00
|
|
|
return $this->$name();
|
2026-07-03 16:08:07 +08:00
|
|
|
} else if (property_exists($this, $name)) {
|
2026-07-03 16:07:27 +08:00
|
|
|
return $this->$name;
|
2026-07-03 16:08:07 +08:00
|
|
|
} else {
|
|
|
|
|
throw new Exception('Property|Method "' . $name . '" does not exist.');
|
2026-07-03 16:07:27 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 13:54:34 +08:00
|
|
|
}
|