From a088b6f9c53d58d1288390f183a1c102607e08f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 16 Nov 2020 13:46:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Client/ClientDriver.php | 19 ++++++++++++++----- System/Abstracts/BaseApplication.php | 6 ++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/HttpServer/Client/ClientDriver.php b/HttpServer/Client/ClientDriver.php index fae7747a..8760ad74 100644 --- a/HttpServer/Client/ClientDriver.php +++ b/HttpServer/Client/ClientDriver.php @@ -5,6 +5,7 @@ namespace HttpServer\Client; use Snowflake\Abstracts\Component; +use Swoole\Coroutine; /** @@ -14,9 +15,17 @@ use Snowflake\Abstracts\Component; class ClientDriver extends Component { - public function __call($name) - { + /** + * @param $name + * @return IClient + */ + public function __call($name): IClient + { + if (Coroutine::getCid() > 0) { + return Client::NewRequest(); + } else { + return Curl::NewRequest(); + } + } - } - -} \ No newline at end of file +} diff --git a/System/Abstracts/BaseApplication.php b/System/Abstracts/BaseApplication.php index 03f0cdff..e7c43e51 100644 --- a/System/Abstracts/BaseApplication.php +++ b/System/Abstracts/BaseApplication.php @@ -12,8 +12,10 @@ namespace Snowflake\Abstracts; use Exception; use HttpServer\Client\Client; +use HttpServer\Client\ClientDriver; use HttpServer\Client\Curl; use HttpServer\Client\Http2; +use HttpServer\Client\IClient; use HttpServer\Http\Request; use HttpServer\Http\Response; use HttpServer\Route\Router; @@ -50,7 +52,7 @@ use Database\DatabasesProviders; * @property Logger $logger * @property Jwt $jwt * @property BaseGoto $goto - * @property Client $client + * @property IClient $client * @property Producer $kafka */ abstract class BaseApplication extends Service @@ -379,7 +381,7 @@ abstract class BaseApplication extends Service 'error' => ['class' => ErrorHandler::class], 'event' => ['class' => Event::class], 'annotation' => ['class' => Annotation::class], - 'client' => ['class' => Client::class], + 'client' => ['class' => ClientDriver::class], 'connections' => ['class' => Connection::class], 'redis_connections' => ['class' => SRedis::class], 'pool' => ['class' => SPool::class],