Skip to content

Commit

Permalink
格式化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
brjunsuc committed Mar 28, 2022
1 parent 0425e2b commit 45934ae
Showing 1 changed file with 110 additions and 110 deletions.
220 changes: 110 additions & 110 deletions Src/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,114 +21,114 @@

class Request
{
protected $apiUrl = '';
/**
* @var Client
*/
protected $httpClient;
protected $defaultHttpClientConfig = [
'headers' => [],
'verify' => false,
'curl.options' => [
CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1,
],
'connect_timeout' => 3,
'timeout' => 10
];
protected static $middlewareMap = [];
protected $cache;

/**
* @var Response
*/
protected $response;
/**
* @var string
*/
protected $responseContent;

public function __construct(CacheInterface $cache = null)
{
$header = [];

if (defined('W7_CLOUD_SDK_LOCAL') && !empty(W7_CLOUD_SDK_LOCAL)) {
$this->apiUrl = W7_CLOUD_SDK_LOCAL_URL;
}

if (defined('W7_CLOUD_SDK_CUSTOM_AGENT') && !empty(W7_CLOUD_SDK_CUSTOM_AGENT)) {
$header['User-Agent'] = W7_CLOUD_SDK_CUSTOM_AGENT;
}

$this->defaultHttpClientConfig['headers'] = array_merge([], $this->defaultHttpClientConfig['headers'], $header);
$this->cache = $cache;
}

public function debug()
{
$this->defaultHttpClientConfig['debug'] = true;
return $this;
}

public function setConnectTimeout($seconds) {
$this->defaultHttpClientConfig['connect_timeout'] = $seconds;
return $this;
}

public function setRequestTimeout($seconds) {
$this->defaultHttpClientConfig['timeout'] = $seconds;
return $this;
}

public static function setEnvCustom($agent)
{
!defined('W7_CLOUD_SDK_CUSTOM_AGENT') && define('W7_CLOUD_SDK_CUSTOM_AGENT', $agent);
}

public static function setEnvLocal($url = 'http://127.0.0.1/', $authCode = '')
{
!defined('W7_CLOUD_SDK_LOCAL') && define('W7_CLOUD_SDK_LOCAL', 1);
!defined('W7_CLOUD_SDK_LOCAL_URL') && define('W7_CLOUD_SDK_LOCAL_URL', $url);
!defined('W7_CLOUD_SDK_AUTHKEY') && define('W7_CLOUD_SDK_AUTHKEY', $authCode);
}

public function getClient()
{
if (!$this->httpClient) {
if (empty($this->defaultHttpClientConfig['handler'])) {
$this->defaultHttpClientConfig['handler'] = HandlerStack::create();
}

$this->defaultHttpClientConfig['handler']->push(function ($handler) {
return new RetryMiddleware($handler, $this->defaultHttpClientConfig);
});
foreach (static::$middlewareMap as $middleware) {
$this->defaultHttpClientConfig['handler']->push($middleware);
}

$this->httpClient = new Client($this->defaultHttpClientConfig);
}

return $this->httpClient;
}

public function withHeader($key, $value)
{
$this->defaultHttpClientConfig['headers'][$key] = $value;
return $this;
}

public static function registerMiddleware(Closure $middleware)
{
static::$middlewareMap[] = $middleware;
}

public function getResponse()
{
return $this->response;
}

public function getResponseContent()
{
return $this->responseContent;
}
protected $apiUrl = '';
/**
* @var Client
*/
protected $httpClient;
protected $defaultHttpClientConfig = [
'headers' => [],
'verify' => false,
'curl.options' => [
CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1,
],
'connect_timeout' => 3,
'timeout' => 10
];
protected static $middlewareMap = [];
protected $cache;

/**
* @var Response
*/
protected $response;
/**
* @var string
*/
protected $responseContent;

public function __construct(CacheInterface $cache = null)
{
$header = [];

if (defined('W7_CLOUD_SDK_LOCAL') && !empty(W7_CLOUD_SDK_LOCAL)) {
$this->apiUrl = W7_CLOUD_SDK_LOCAL_URL;
}

if (defined('W7_CLOUD_SDK_CUSTOM_AGENT') && !empty(W7_CLOUD_SDK_CUSTOM_AGENT)) {
$header['User-Agent'] = W7_CLOUD_SDK_CUSTOM_AGENT;
}

$this->defaultHttpClientConfig['headers'] = array_merge([], $this->defaultHttpClientConfig['headers'], $header);
$this->cache = $cache;
}

public function debug()
{
$this->defaultHttpClientConfig['debug'] = true;
return $this;
}

public function setConnectTimeout($seconds) {
$this->defaultHttpClientConfig['connect_timeout'] = $seconds;
return $this;
}

public function setRequestTimeout($seconds) {
$this->defaultHttpClientConfig['timeout'] = $seconds;
return $this;
}

public static function setEnvCustom($agent)
{
!defined('W7_CLOUD_SDK_CUSTOM_AGENT') && define('W7_CLOUD_SDK_CUSTOM_AGENT', $agent);
}

public static function setEnvLocal($url = 'http://127.0.0.1/', $authCode = '')
{
!defined('W7_CLOUD_SDK_LOCAL') && define('W7_CLOUD_SDK_LOCAL', 1);
!defined('W7_CLOUD_SDK_LOCAL_URL') && define('W7_CLOUD_SDK_LOCAL_URL', $url);
!defined('W7_CLOUD_SDK_AUTHKEY') && define('W7_CLOUD_SDK_AUTHKEY', $authCode);
}

public function getClient()
{
if (!$this->httpClient) {
if (empty($this->defaultHttpClientConfig['handler'])) {
$this->defaultHttpClientConfig['handler'] = HandlerStack::create();
}

$this->defaultHttpClientConfig['handler']->push(function ($handler) {
return new RetryMiddleware($handler, $this->defaultHttpClientConfig);
});
foreach (static::$middlewareMap as $middleware) {
$this->defaultHttpClientConfig['handler']->push($middleware);
}

$this->httpClient = new Client($this->defaultHttpClientConfig);
}

return $this->httpClient;
}

public function withHeader($key, $value)
{
$this->defaultHttpClientConfig['headers'][$key] = $value;
return $this;
}

public static function registerMiddleware(Closure $middleware)
{
static::$middlewareMap[] = $middleware;
}

public function getResponse()
{
return $this->response;
}

public function getResponseContent()
{
return $this->responseContent;
}
}

0 comments on commit 45934ae

Please sign in to comment.