1 | <?php |
||
2 | |||
3 | namespace App\Renderer; |
||
4 | |||
5 | use Psr\Http\Message\ResponseInterface; |
||
6 | |||
7 | final class JsonRenderer |
||
8 | { |
||
9 | public function json( |
||
10 | ResponseInterface $response, |
||
11 | mixed $data = null, |
||
12 | ): ResponseInterface { |
||
13 | $response = $response->withHeader('Content-Type', 'application/json'); |
||
14 | |||
15 | $response->getBody()->write( |
||
16 | (string)json_encode( |
||
17 | $data, |
||
18 | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR |
||
19 | ) |
||
20 | ); |
||
21 | |||
22 | return $response; |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
23 | } |
||
24 | } |
||
25 |