4 use Psr\Http\Message\RequestInterface;
5 use Psr\Http\Message\ResponseInterface;
6 use Psr\Http\Message\UriInterface;
9 * Represents data at the point after it was transferred either successfully
10 * or after a network error.
12 final class TransferStats
16 private $transferTime;
17 private $handlerStats;
18 private $handlerErrorData;
21 * @param RequestInterface $request Request that was sent.
22 * @param ResponseInterface $response Response received (if any)
23 * @param null $transferTime Total handler transfer time.
24 * @param mixed $handlerErrorData Handler error data.
25 * @param array $handlerStats Handler specific stats.
27 public function __construct(
28 RequestInterface $request,
29 ResponseInterface $response = null,
31 $handlerErrorData = null,
34 $this->request = $request;
35 $this->response = $response;
36 $this->transferTime = $transferTime;
37 $this->handlerErrorData = $handlerErrorData;
38 $this->handlerStats = $handlerStats;
42 * @return RequestInterface
44 public function getRequest()
46 return $this->request;
50 * Returns the response that was received (if any).
52 * @return ResponseInterface|null
54 public function getResponse()
56 return $this->response;
60 * Returns true if a response was received.
64 public function hasResponse()
66 return $this->response !== null;
70 * Gets handler specific error data.
72 * This might be an exception, a integer representing an error code, or
73 * anything else. Relying on this value assumes that you know what handler
78 public function getHandlerErrorData()
80 return $this->handlerErrorData;
84 * Get the effective URI the request was sent to.
86 * @return UriInterface
88 public function getEffectiveUri()
90 return $this->request->getUri();
94 * Get the estimated time the request was being transferred by the handler.
96 * @return float Time in seconds.
98 public function getTransferTime()
100 return $this->transferTime;
104 * Gets an array of all of the handler specific transfer data.
108 public function getHandlerStats()
110 return $this->handlerStats;
114 * Get a specific handler statistic from the handler by name.
116 * @param string $stat Handler specific transfer stat to retrieve.
120 public function getHandlerStat($stat)
122 return isset($this->handlerStats[$stat])
123 ? $this->handlerStats[$stat]