Files
kiri-client/src/Client.php
T

44 lines
686 B
PHP
Raw Normal View History

2021-09-29 16:31:42 +08:00
<?php
2021-09-30 17:24:06 +08:00
namespace Http\Client;
2021-09-29 16:31:42 +08:00
2021-10-26 10:59:01 +08:00
use Kiri\Context;
2021-10-09 15:48:59 +08:00
2021-09-29 16:31:42 +08:00
/**
2021-10-09 15:48:59 +08:00
* @mixin CoroutineClient|Curl
2021-09-29 16:31:42 +08:00
*/
2021-10-09 15:48:59 +08:00
class Client
2021-09-29 16:31:42 +08:00
{
2021-12-11 16:39:46 +08:00
private CoroutineClient|Curl|AsyncClient $abstracts;
2021-09-29 16:31:42 +08:00
/**
2021-10-09 15:48:59 +08:00
* @param string $host
* @param int $port
* @param bool $isSsl
2021-09-29 16:31:42 +08:00
*/
2021-10-09 15:48:59 +08:00
public function __construct(string $host, int $port, bool $isSsl = false)
2021-09-29 16:31:42 +08:00
{
2021-10-09 15:48:59 +08:00
if (Context::inCoroutine()) {
$this->abstracts = new CoroutineClient($host, $port, $isSsl);
2021-09-29 16:31:42 +08:00
} else {
2021-12-24 14:47:12 +08:00
$this->abstracts = new Curl($host, $port, $isSsl);
2021-09-29 16:31:42 +08:00
}
}
/**
2021-10-09 15:48:59 +08:00
* @param string $name
* @param array $arguments
* @return mixed
2021-09-29 16:31:42 +08:00
*/
2021-10-09 15:48:59 +08:00
public function __call(string $name, array $arguments)
2021-09-29 16:31:42 +08:00
{
2021-10-09 15:48:59 +08:00
return $this->abstracts->{$name}(...$arguments);
2021-09-29 16:31:42 +08:00
}
}