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],