Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
JsonResponse | |
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
render | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Miniframe\Response; |
4 | |
5 | use Miniframe\Core\Response; |
6 | |
7 | class JsonResponse extends Response |
8 | { |
9 | /** |
10 | * The response data |
11 | * |
12 | * @var mixed |
13 | */ |
14 | private $data; |
15 | |
16 | /** |
17 | * Initializes a Json Response |
18 | * |
19 | * @param mixed $data Response data. |
20 | */ |
21 | public function __construct($data) |
22 | { |
23 | $this->data = $data; |
24 | $this->addHeader('Content-type: application/json'); |
25 | } |
26 | |
27 | /** |
28 | * Returns the JSON encoded data collection |
29 | * |
30 | * @return string |
31 | */ |
32 | public function render(): string |
33 | { |
34 | return json_encode($this->data, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR); |
35 | } |
36 | } |