| Total Complexity | 5 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class JsonView extends AbstractView |
||
| 10 | { |
||
| 11 | const JSON_ROOT = self::class; |
||
| 12 | protected $jsonOption = 0; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @param array $data |
||
| 16 | * @return ResponseInterface |
||
| 17 | */ |
||
| 18 | public function render(array $data = []): ResponseInterface |
||
| 19 | { |
||
| 20 | $jsonData = array_key_exists(static::JSON_ROOT, $data) ? $data[static::JSON_ROOT] : $data; |
||
| 21 | $this->getEmptyBody()->write(json_encode($jsonData, $this->jsonOption)); |
||
| 22 | |||
| 23 | return $this->response |
||
| 24 | ->withHeader('Content-Type', 'application/json'); |
||
| 25 | } |
||
| 26 | |||
| 27 | public function renderJson($value): ResponseInterface |
||
| 28 | { |
||
| 29 | return $this->render([static::JSON_ROOT => $value]); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @return int |
||
| 34 | */ |
||
| 35 | public function getJsonOption() |
||
| 36 | { |
||
| 37 | return $this->jsonOption; |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * |
||
| 42 | * @param int $jsonOption |
||
| 43 | * @return $this |
||
| 44 | */ |
||
| 45 | public function setJsonOption($jsonOption) |
||
| 50 | } |
||
| 51 | } |
||
| 52 |