Files
kiri-core/http-helper/Client/HttpClient.php
T

65 lines
936 B
PHP
Raw Normal View History

2020-11-16 01:12:06 +08:00
<?php
2021-08-17 16:43:50 +08:00
namespace Http\Client;
2020-11-16 01:12:06 +08:00
2021-08-13 14:13:56 +08:00
use JetBrains\PhpStorm\Pure;
2021-08-11 01:04:57 +08:00
use Kiri\Abstracts\Component;
2021-08-13 14:23:18 +08:00
use ReflectionException;
2020-11-16 13:46:24 +08:00
use Swoole\Coroutine;
2020-11-16 01:12:06 +08:00
/**
* Class ClientDriver
2021-08-17 16:43:50 +08:00
* @package Http\Client
2021-08-13 14:23:18 +08:00
* @mixin Client
2020-11-16 01:12:06 +08:00
*/
2020-11-16 19:00:03 +08:00
class HttpClient extends Component
2020-11-16 01:12:06 +08:00
{
2020-11-16 13:46:24 +08:00
/**
* @return IClient
*/
2020-11-17 10:36:51 +08:00
public static function NewRequest(): IClient
2020-11-16 13:46:24 +08:00
{
2021-08-13 14:13:56 +08:00
if (Coroutine::getCid() > -1) {
return Client::NewRequest();
}
return Curl::NewRequest();
2020-11-16 13:46:24 +08:00
}
2020-11-16 19:00:03 +08:00
/**
2021-08-13 14:13:56 +08:00
* @return Curl
2020-11-16 19:00:03 +08:00
*/
2021-08-13 14:13:56 +08:00
#[Pure] public function getCurl(): Curl
2020-11-16 19:00:03 +08:00
{
2021-08-13 14:13:56 +08:00
return Curl::NewRequest();
2020-11-16 19:00:03 +08:00
}
2021-08-13 14:13:56 +08:00
/**
* @return Client
*/
#[Pure] public function getCoroutine(): Client
{
return Client::NewRequest();
}
2021-08-13 14:23:18 +08:00
/**
* @param string $name
* @param array $arguments
* @return void
*/
public function __call(string $name, array $arguments)
{
if (!method_exists($this, $name)) {
return static::NewRequest()->{$name}(...$arguments);
}
return $this->{$name}(...$arguments);
}
2020-11-16 13:46:24 +08:00
}