Skip to content

Commit a7d5d26

Browse files
authored
Merge pull request #6556 from kenjis/fix-ResponseInterface
fix: ResponseInterface (1)
2 parents 25c5d8b + 9fbd5f8 commit a7d5d26

File tree

10 files changed

+125
-64
lines changed

10 files changed

+125
-64
lines changed

system/CodeIgniter.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ class CodeIgniter
138138
* to keep from setting headers/cookies/etc
139139
*
140140
* @var bool
141+
*
142+
* @deprecated No longer used.
141143
*/
142144
protected $useSafeOutput = false;
143145

@@ -340,7 +342,7 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
340342
return $response;
341343
}
342344

343-
$this->response->pretend($this->useSafeOutput)->send();
345+
$this->response->send();
344346
$this->callExit(EXIT_SUCCESS);
345347

346348
return;
@@ -371,6 +373,8 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
371373
* not complain when ini_set() function is used.
372374
*
373375
* @return $this
376+
*
377+
* @deprecated No longer used.
374378
*/
375379
public function useSafeOutput(bool $safe = true)
376380
{
@@ -433,7 +437,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
433437

434438
// If a ResponseInterface instance is returned then send it back to the client and stop
435439
if ($possibleResponse instanceof ResponseInterface) {
436-
return $returnResponse ? $possibleResponse : $possibleResponse->pretend($this->useSafeOutput)->send();
440+
return $returnResponse ? $possibleResponse : $possibleResponse->send();
437441
}
438442

439443
if ($possibleResponse instanceof Request) {
@@ -1057,7 +1061,7 @@ public function spoofRequestMethod()
10571061
*/
10581062
protected function sendResponse()
10591063
{
1060-
$this->response->pretend($this->useSafeOutput)->send();
1064+
$this->response->send();
10611065
}
10621066

10631067
/**

system/HTTP/MessageInterface.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ interface MessageInterface
2727
*/
2828
public function setBody($data);
2929

30+
/**
31+
* Gets the body of the message.
32+
*
33+
* @return string|null
34+
*
35+
* @TODO Incompatible return type with PSR-7
36+
*/
37+
public function getBody();
38+
3039
/**
3140
* Appends data to the body of the current message.
3241
*
@@ -48,6 +57,17 @@ public function populateHeaders(): void;
4857
*/
4958
public function headers(): array;
5059

60+
/**
61+
* Checks if a header exists by the given case-insensitive name.
62+
*
63+
* @param string $name Case-insensitive header field name.
64+
*
65+
* @return bool Returns true if any header names match the given header
66+
* name using a case-insensitive string comparison. Returns false if
67+
* no matching header name is found in the message.
68+
*/
69+
public function hasHeader(string $name): bool;
70+
5171
/**
5272
* Returns a single Header object. If multiple headers with the same
5373
* name exist, then will return an array of header objects.
@@ -58,6 +78,19 @@ public function headers(): array;
5878
*/
5979
public function header($name);
6080

81+
/**
82+
* Retrieves a comma-separated string of the values for a single header.
83+
*
84+
* This method returns all of the header values of the given
85+
* case-insensitive header name as a string concatenated together using
86+
* a comma.
87+
*
88+
* NOTE: Not all header values may be appropriately represented using
89+
* comma concatenation. For such headers, use getHeader() instead
90+
* and supply your own delimiter when concatenating.
91+
*/
92+
public function getHeaderLine(string $name): string;
93+
6194
/**
6295
* Sets a header and it's value.
6396
*

system/HTTP/Response.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,13 @@ public function __construct($config)
188188

189189
/**
190190
* Turns "pretend" mode on or off to aid in testing.
191+
*
191192
* Note that this is not a part of the interface so
192193
* should not be relied on outside of internal testing.
193194
*
194195
* @return $this
196+
*
197+
* @testTag only available to test code
195198
*/
196199
public function pretend(bool $pretend = true)
197200
{

system/HTTP/ResponseInterface.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@
2828
* - Status code and reason phrase
2929
* - Headers
3030
* - Message body
31-
*
32-
* @mixin RedirectResponse
3331
*/
34-
interface ResponseInterface
32+
interface ResponseInterface extends MessageInterface
3533
{
3634
/**
3735
* Constants for status codes.
@@ -130,7 +128,7 @@ public function getStatusCode(): int;
130128
* provided status code; if none is provided, will
131129
* default to the IANA name.
132130
*
133-
* @return self
131+
* @return $this
134132
*
135133
* @throws InvalidArgumentException For invalid status code arguments.
136134
*/
@@ -153,7 +151,7 @@ public function getReason(): string;
153151
/**
154152
* Sets the date header
155153
*
156-
* @return ResponseInterface
154+
* @return $this
157155
*/
158156
public function setDate(DateTime $date);
159157

@@ -164,6 +162,8 @@ public function setDate(DateTime $date);
164162
* preferably, an instance of DateTime.
165163
*
166164
* @param DateTime|string $date
165+
*
166+
* @return $this
167167
*/
168168
public function setLastModified($date);
169169

@@ -172,7 +172,7 @@ public function setLastModified($date);
172172
*
173173
* @see http://tools.ietf.org/html/rfc5988
174174
*
175-
* @return Response
175+
* @return $this
176176
*
177177
* @todo Recommend moving to Pager
178178
*/
@@ -182,7 +182,7 @@ public function setLink(PagerInterface $pager);
182182
* Sets the Content Type header for this response with the mime type
183183
* and, optionally, the charset.
184184
*
185-
* @return ResponseInterface
185+
* @return $this
186186
*/
187187
public function setContentType(string $mime, string $charset = 'UTF-8');
188188

@@ -202,7 +202,7 @@ public function setJSON($body, bool $unencoded = false);
202202
/**
203203
* Returns the current body, converted to JSON is it isn't already.
204204
*
205-
* @return mixed|string
205+
* @return bool|string|null
206206
*
207207
* @throws InvalidArgumentException If the body property is not array.
208208
*/
@@ -220,7 +220,7 @@ public function setXML($body);
220220
/**
221221
* Retrieves the current body into XML and returns it.
222222
*
223-
* @return mixed|string
223+
* @return bool|string|null
224224
*
225225
* @throws InvalidArgumentException If the body property is not array.
226226
*/
@@ -235,6 +235,8 @@ public function getXML();
235235
/**
236236
* Sets the appropriate headers to ensure this response
237237
* is not cached by the browsers.
238+
*
239+
* @return $this
238240
*/
239241
public function noCache();
240242

@@ -262,7 +264,7 @@ public function noCache();
262264
* - proxy-revalidate
263265
* - no-transform
264266
*
265-
* @return ResponseInterface
267+
* @return $this
266268
*/
267269
public function setCache(array $options = []);
268270

@@ -273,21 +275,21 @@ public function setCache(array $options = []);
273275
/**
274276
* Sends the output to the browser.
275277
*
276-
* @return ResponseInterface
278+
* @return $this
277279
*/
278280
public function send();
279281

280282
/**
281283
* Sends the headers of this HTTP request to the browser.
282284
*
283-
* @return Response
285+
* @return $this
284286
*/
285287
public function sendHeaders();
286288

287289
/**
288290
* Sends the Body of the message to the browser.
289291
*
290-
* @return Response
292+
* @return $this
291293
*/
292294
public function sendBody();
293295

system/HTTP/ResponseTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function setJSON($body, bool $unencoded = false)
252252
/**
253253
* Returns the current body, converted to JSON is it isn't already.
254254
*
255-
* @return mixed|string
255+
* @return bool|string|null
256256
*
257257
* @throws InvalidArgumentException If the body property is not array.
258258
*/
@@ -284,7 +284,7 @@ public function setXML($body)
284284
/**
285285
* Retrieves the current body into XML and returns it.
286286
*
287-
* @return mixed|string
287+
* @return bool|string|null
288288
*
289289
* @throws InvalidArgumentException If the body property is not array.
290290
*/
@@ -430,7 +430,7 @@ public function setLastModified($date)
430430
/**
431431
* Sends the output to the browser.
432432
*
433-
* @return Response
433+
* @return $this
434434
*/
435435
public function send()
436436
{

0 commit comments

Comments
 (0)