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