| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\GuzzleHttp; |
| 4 |
|
| 5 |
use Dudlewebs\WPMCS\s3\Psr\Http\Message\RequestInterface; |
| 6 |
use Dudlewebs\WPMCS\s3\Psr\Http\Message\ResponseInterface; |
| 7 |
use Dudlewebs\WPMCS\s3\Psr\Http\Message\UriInterface; |
| 8 |
/** |
| 9 |
* Represents data at the point after it was transferred either successfully |
| 10 |
* or after a network error. |
| 11 |
*/ |
| 12 |
final class TransferStats |
| 13 |
{ |
| 14 |
private $request; |
| 15 |
private $response; |
| 16 |
private $transferTime; |
| 17 |
private $handlerStats; |
| 18 |
private $handlerErrorData; |
| 19 |
/** |
| 20 |
* @param RequestInterface $request Request that was sent. |
| 21 |
* @param ResponseInterface|null $response Response received (if any) |
| 22 |
* @param float|null $transferTime Total handler transfer time. |
| 23 |
* @param mixed $handlerErrorData Handler error data. |
| 24 |
* @param array $handlerStats Handler specific stats. |
| 25 |
*/ |
| 26 |
public function __construct(RequestInterface $request, ResponseInterface $response = null, $transferTime = null, $handlerErrorData = null, $handlerStats = []) |
| 27 |
{ |
| 28 |
$this->request = $request; |
| 29 |
$this->response = $response; |
| 30 |
$this->transferTime = $transferTime; |
| 31 |
$this->handlerErrorData = $handlerErrorData; |
| 32 |
$this->handlerStats = $handlerStats; |
| 33 |
} |
| 34 |
/** |
| 35 |
* @return RequestInterface |
| 36 |
*/ |
| 37 |
public function getRequest() |
| 38 |
{ |
| 39 |
return $this->request; |
| 40 |
} |
| 41 |
/** |
| 42 |
* Returns the response that was received (if any). |
| 43 |
* |
| 44 |
* @return ResponseInterface|null |
| 45 |
*/ |
| 46 |
public function getResponse() |
| 47 |
{ |
| 48 |
return $this->response; |
| 49 |
} |
| 50 |
/** |
| 51 |
* Returns true if a response was received. |
| 52 |
* |
| 53 |
* @return bool |
| 54 |
*/ |
| 55 |
public function hasResponse() |
| 56 |
{ |
| 57 |
return $this->response !== null; |
| 58 |
} |
| 59 |
/** |
| 60 |
* Gets handler specific error data. |
| 61 |
* |
| 62 |
* This might be an exception, a integer representing an error code, or |
| 63 |
* anything else. Relying on this value assumes that you know what handler |
| 64 |
* you are using. |
| 65 |
* |
| 66 |
* @return mixed |
| 67 |
*/ |
| 68 |
public function getHandlerErrorData() |
| 69 |
{ |
| 70 |
return $this->handlerErrorData; |
| 71 |
} |
| 72 |
/** |
| 73 |
* Get the effective URI the request was sent to. |
| 74 |
* |
| 75 |
* @return UriInterface |
| 76 |
*/ |
| 77 |
public function getEffectiveUri() |
| 78 |
{ |
| 79 |
return $this->request->getUri(); |
| 80 |
} |
| 81 |
/** |
| 82 |
* Get the estimated time the request was being transferred by the handler. |
| 83 |
* |
| 84 |
* @return float|null Time in seconds. |
| 85 |
*/ |
| 86 |
public function getTransferTime() |
| 87 |
{ |
| 88 |
return $this->transferTime; |
| 89 |
} |
| 90 |
/** |
| 91 |
* Gets an array of all of the handler specific transfer data. |
| 92 |
* |
| 93 |
* @return array |
| 94 |
*/ |
| 95 |
public function getHandlerStats() |
| 96 |
{ |
| 97 |
return $this->handlerStats; |
| 98 |
} |
| 99 |
/** |
| 100 |
* Get a specific handler statistic from the handler by name. |
| 101 |
* |
| 102 |
* @param string $stat Handler specific transfer stat to retrieve. |
| 103 |
* |
| 104 |
* @return mixed|null |
| 105 |
*/ |
| 106 |
public function getHandlerStat($stat) |
| 107 |
{ |
| 108 |
return isset($this->handlerStats[$stat]) ? $this->handlerStats[$stat] : null; |
| 109 |
} |
| 110 |
} |
| 111 |
|