2525 */
2626class Response
2727{
28- private $ response ;
28+ private $ httpResponse ;
2929
3030 private $ httpClient ;
3131
3232 /**
3333 * A Result can be resolved many times. This variable contains the last resolve result.
34+ * Null means that the result has never been resolved.
3435 *
3536 * @var bool|NetworkException|HttpException|null
3637 */
3738 private $ resolveResult ;
3839
3940 public function __construct (ResponseInterface $ response , HttpClientInterface $ httpClient )
4041 {
41- $ this ->response = $ response ;
42+ $ this ->httpResponse = $ response ;
4243 $ this ->httpClient = $ httpClient ;
4344 }
4445
@@ -52,7 +53,8 @@ public function __destruct()
5253 /**
5354 * Make sure the actual request is executed.
5455 *
55- * @param float|null $timeout Duration in seconds before aborting. When null wait until the end of execution.
56+ * @param float|null $timeout Duration in seconds before aborting. When null wait
57+ * until the end of execution. Using 0 means non-blocking
5658 *
5759 * @return bool whether the request is executed or not
5860 *
@@ -74,7 +76,7 @@ public function resolve(?float $timeout = null): bool
7476 }
7577
7678 try {
77- foreach ($ this ->httpClient ->stream ($ this ->response , $ timeout ) as $ chunk ) {
79+ foreach ($ this ->httpClient ->stream ($ this ->httpResponse , $ timeout ) as $ chunk ) {
7880 if ($ chunk ->isTimeout ()) {
7981 return false ;
8082 }
@@ -83,21 +85,21 @@ public function resolve(?float $timeout = null): bool
8385 }
8486 }
8587
86- $ statusCode = $ this ->response ->getStatusCode ();
88+ $ statusCode = $ this ->httpResponse ->getStatusCode ();
8789 } catch (TransportExceptionInterface $ e ) {
8890 throw $ this ->resolveResult = new NetworkException ('Could not contact remote server. ' , 0 , $ e );
8991 }
9092
9193 if (500 <= $ statusCode ) {
92- throw $ this ->resolveResult = new ServerException ($ this ->response );
94+ throw $ this ->resolveResult = new ServerException ($ this ->httpResponse );
9395 }
9496
9597 if (400 <= $ statusCode ) {
96- throw $ this ->resolveResult = new ClientException ($ this ->response );
98+ throw $ this ->resolveResult = new ClientException ($ this ->httpResponse );
9799 }
98100
99101 if (300 <= $ statusCode ) {
100- throw $ this ->resolveResult = new RedirectionException ($ this ->response );
102+ throw $ this ->resolveResult = new RedirectionException ($ this ->httpResponse );
101103 }
102104
103105 return $ this ->resolveResult = true ;
@@ -116,45 +118,45 @@ public function info(): array
116118 {
117119 return [
118120 'resolved ' => null !== $ this ->resolveResult ,
119- 'response ' => $ this ->response ,
120- 'status ' => (int ) $ this ->response ->getInfo ('http_code ' ),
121+ 'response ' => $ this ->httpResponse ,
122+ 'status ' => (int ) $ this ->httpResponse ->getInfo ('http_code ' ),
121123 ];
122124 }
123125
124126 public function cancel (): void
125127 {
126- $ this ->response ->cancel ();
128+ $ this ->httpResponse ->cancel ();
127129 $ this ->resolveResult = false ;
128130 }
129131
130132 public function getHeaders (): array
131133 {
132134 $ this ->resolve ();
133135
134- return $ this ->response ->getHeaders (false );
136+ return $ this ->httpResponse ->getHeaders (false );
135137 }
136138
137139 public function getContent (): string
138140 {
139141 $ this ->resolve ();
140142
141- return $ this ->response ->getContent (false );
143+ return $ this ->httpResponse ->getContent (false );
142144 }
143145
144146 public function toArray (): array
145147 {
146148 $ this ->resolve ();
147149
148- return $ this ->response ->toArray (false );
150+ return $ this ->httpResponse ->toArray (false );
149151 }
150152
151153 public function getStatusCode (): int
152154 {
153- return $ this ->response ->getStatusCode ();
155+ return $ this ->httpResponse ->getStatusCode ();
154156 }
155157
156158 public function toStream (): ResultStream
157159 {
158- return new ResponseBodyStream ($ this ->httpClient ->stream ($ this ->response ));
160+ return new ResponseBodyStream ($ this ->httpClient ->stream ($ this ->httpResponse ));
159161 }
160162}
0 commit comments