|
16 | 16 | use PhpRestfulApiResponse\Contracts\PhpRestfulApiResponse;
|
17 | 17 | use Zend\Diactoros\MessageTrait;
|
18 | 18 | use InvalidArgumentException;
|
| 19 | +use Zend\Diactoros\Response\InjectContentTypeTrait; |
19 | 20 | use Zend\Diactoros\Response\JsonResponse;
|
20 | 21 |
|
21 | 22 | class Response implements PhpRestfulApiResponse
|
22 | 23 | {
|
23 |
| - use MessageTrait; |
| 24 | + use MessageTrait, InjectContentTypeTrait; |
24 | 25 |
|
25 | 26 | const MIN_STATUS_CODE_VALUE = 100;
|
26 | 27 | const MAX_STATUS_CODE_VALUE = 599;
|
@@ -131,6 +132,7 @@ public function __construct($body = 'php://memory', int $status = 200, $errorCod
|
131 | 132 | $this->setStatusCode($status);
|
132 | 133 | $this->setErrorCode($errorCode);
|
133 | 134 | $this->stream = $this->getStream($body, 'wb+');
|
| 135 | + $headers = $this->injectContentType('application/json', $headers); |
134 | 136 | $this->setHeaders($headers);
|
135 | 137 | }
|
136 | 138 |
|
@@ -178,7 +180,6 @@ public function withArray($data, $code = 200, array $headers = [])
|
178 | 180 | $new = clone $this;
|
179 | 181 | $new->setStatusCode($code);
|
180 | 182 | $new->getBody()->write($this->jsonEncode($data));
|
181 |
| - $new = $new->withHeader('Content-Type', 'application/json'); |
182 | 183 | $new->headers = array_merge($new->headers, $headers);
|
183 | 184 | return $new;
|
184 | 185 | }
|
@@ -262,7 +263,6 @@ public function withError($message, int $statusCode, $errorCode = null, array $h
|
262 | 263 | ]
|
263 | 264 | )
|
264 | 265 | );
|
265 |
| - $new = $new->withHeader('Content-Type', 'application/json'); |
266 | 266 | $new->headers = array_merge($new->headers, $headers);
|
267 | 267 | return $new;
|
268 | 268 | }
|
|
0 commit comments