This commit is contained in:
2020-11-17 10:44:29 +08:00
parent ec99186fe2
commit d7827c424c
3 changed files with 188 additions and 56 deletions
+1 -6
View File
@@ -17,16 +17,11 @@ class HttpClient extends Component
{ {
/** /**
* @param $name
* @return IClient * @return IClient
*/ */
public static function NewRequest(): IClient public static function NewRequest(): IClient
{ {
if (Coroutine::getCid() > 0) { return Coroutine::getCid() > 0 ? Client::NewRequest() : Curl::NewRequest();
return Client::NewRequest();
} else {
return Curl::NewRequest();
}
} }
+185 -50
View File
@@ -8,68 +8,203 @@ interface IClient
{ {
/** /**
* @param string $path * @param string $path
* @param array $params * @param array $params
* @return mixed * @return mixed
*/ */
public function get(string $path, array $params = []); public function get(string $path, array $params = []);
/** /**
* @param string $path * @param string $path
* @param array $params * @param array $params
* @return mixed * @return mixed
*/ */
public function post(string $path, array $params = []); public function post(string $path, array $params = []);
/** /**
* @param string $path * @param string $path
* @param array $params * @param array $params
* @return mixed * @return mixed
*/ */
public function delete(string $path, array $params = []); public function delete(string $path, array $params = []);
/** /**
* @param string $path * @param string $path
* @param array $params * @param array $params
* @return mixed * @return mixed
*/ */
public function options(string $path, array $params = []); public function options(string $path, array $params = []);
/** /**
* @param string $path * @param string $path
* @param array $params * @param array $params
* @return mixed * @return mixed
*/ */
public function upload(string $path, array $params = []); public function upload(string $path, array $params = []);
/** /**
* @param string $path * @param string $path
* @param array $params * @param array $params
* @return mixed * @return mixed
*/ */
public function put(string $path, array $params = []); public function put(string $path, array $params = []);
/** /**
* @param string $path * @param string $path
* @param array $params * @param array $params
* @return mixed * @return mixed
*/ */
public function head(string $path, array $params = []); public function head(string $path, array $params = []);
/** /**
* @param string $method * @param string $method
* @param string $path * @param string $path
* @param array $params * @param array $params
* @return mixed * @return mixed
*/ */
public function request(string $method, string $path, array $params = []); public function request(string $method, string $path, array $params = []);
}
/**
* @param string $host
* @return mixed
*/
public function setHost(string $host);
/**
* @param array $header
* @return mixed
*/
public function setHeader(array $header);
/**
* @param array $header
* @return mixed
*/
public function setHeaders(array $header);
/**
* @param string $key
* @param string $value
* @return mixed
*/
public function addHeader(string $key, string $value);
/**
* @param int $value
* @return mixed
*/
public function setTimeout(int $value);
/**
* @param \Closure|null $value
* @return mixed
*/
public function setCallback(?\Closure $value);
/**
* @param string $value
* @return mixed
*/
public function setMethod(string $value);
/**
* @param bool $isSSL
* @return mixed
*/
public function setIsSSL(bool $isSSL);
/**
* @param string $agent
* @return mixed
*/
public function setAgent(string $agent);
/**
* @param string $errorCodeField
* @return mixed
*/
public function setErrorCodeField(string $errorCodeField);
/**
* @param string $errorMsgField
* @return mixed
*/
public function setErrorMsgField(string $errorMsgField);
/**
* @param bool $use_swoole
* @return mixed
*/
public function setUseSwoole(bool $use_swoole);
/**
* @param string $ssl_cert_file
* @return mixed
*/
public function setSslCertFile(string $ssl_cert_file);
/**
* @param string $ssl_key_file
* @return mixed
*/
public function setSslKeyFile(string $ssl_key_file);
/**
* @param string $ssl_key_file
* @return mixed
*/
public function setCa(string $ssl_key_file);
/**
* @param int $port
* @return mixed
*/
public function setPort(int $port);
/**
* @param string $message
* @return mixed
*/
public function setMessage(string $message);
/**
* @param string $data
* @return mixed
*/
public function setData(string $data);
/**
* @param int $connect_timeout
* @return mixed
*/
public function setConnectTimeout(int $connect_timeout);
}
+2
View File
@@ -51,6 +51,7 @@ use Database\DatabasesProviders;
* @property Memcached $memcached * @property Memcached $memcached
* @property Logger $logger * @property Logger $logger
* @property Jwt $jwt * @property Jwt $jwt
* @property Http2 $http2
* @property BaseGoto $goto * @property BaseGoto $goto
* @property Producer $kafka * @property Producer $kafka
*/ */
@@ -391,6 +392,7 @@ abstract class BaseApplication extends Service
'redis' => ['class' => Redis::class], 'redis' => ['class' => Redis::class],
'jwt' => ['class' => Jwt::class], 'jwt' => ['class' => Jwt::class],
'goto' => ['class' => BaseGoto::class], 'goto' => ['class' => BaseGoto::class],
'http2' => ['class' => Http2::class],
]); ]);
} }
} }