完善 http 客户端

This commit is contained in:
JaguarJack
2020-05-22 14:08:53 +08:00
parent b7d951bdb7
commit ca5e76497c
2 changed files with 86 additions and 37 deletions

View File

@@ -2,6 +2,8 @@
namespace catcher\library\client;
use GuzzleHttp\Promise\Promise;
/**
* http response
*
@@ -12,21 +14,22 @@ namespace catcher\library\client;
class Response implements \ArrayAccess
{
/**
* @var \GuzzleHttp\Psr7\Response
* @var \GuzzleHttp\Psr7\Response|Promise
*/
protected $response;
public function __construct(\GuzzleHttp\Psr7\Response $response)
public function __construct($response)
{
$this->response = $response;
}
/**
*
* @time 2020年05月21
* @return string
* @time 2020年05月22
* @return bool|callable|float|\GuzzleHttp\Psr7\PumpStream|\GuzzleHttp\Psr7\Stream|int|\Iterator|\Psr\Http\Message\StreamInterface|resource|string|null
*/
public function body():string
public function body()
{
return $this->response->getBody();
}
@@ -91,6 +94,19 @@ class Response implements \ArrayAccess
return $this->response->getHeaders();
}
/**
* 异步回调
*
* @time 2020年05月22日
* @param callable $response
* @param callable $exception
* @return \GuzzleHttp\Promise\FulfilledPromise|Promise|\GuzzleHttp\Promise\PromiseInterface|\GuzzleHttp\Promise\RejectedPromise
*/
public function then(callable $response, callable $exception)
{
return $this->response->then($response, $exception);
}
/**
*
* @time 2020年05月21日