Total Complexity | 5 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
14 | class Json extends Response |
||
15 | { |
||
16 | public function __construct($content = null, int $code = Http::CODE_OK, array $config = []) |
||
17 | { |
||
18 | $this->config = $config; |
||
19 | $this->message = (new Message()) |
||
20 | ->withCode($code) |
||
21 | ->withHeaders([ |
||
22 | 'Content-Type' => Http::CONTENT_JSON |
||
23 | ]) |
||
24 | ->withBody($this->encodeAndContainData($content)) |
||
25 | ; |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * Set header and return a string rendered and ready to be echo'ed as response |
||
30 | * |
||
31 | * Header 'Content-type:' will be set using `header` or an injeced 'header_func' through constructor |
||
32 | */ |
||
33 | public function render(): string |
||
34 | { |
||
35 | $this->setHeaders(); |
||
36 | return $this->message->body(); |
||
|
|||
37 | } |
||
38 | |||
39 | private function encodeAndContainData($content): string |
||
48 | } |
||
49 | } |
||
50 |