1 | <?php |
||
7 | final class JsonResponse implements ResponseInterface |
||
8 | { |
||
9 | /** |
||
10 | * @var array|string |
||
11 | */ |
||
12 | private $data; |
||
13 | |||
14 | /** |
||
15 | * @var int |
||
16 | */ |
||
17 | private $httpCode; |
||
18 | |||
19 | /** |
||
20 | * Response constructor. |
||
21 | * |
||
22 | * @param string $data |
||
23 | * @param int $httpCode |
||
24 | */ |
||
25 | public function __construct(string $data, int $httpCode) |
||
38 | |||
39 | /** |
||
40 | * Returns data represented as string. |
||
41 | * |
||
42 | * @return string |
||
43 | */ |
||
44 | public function __toString(): string |
||
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | public function getStatusCode(): int |
||
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | public function getData(): array |
||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | public function isOk(): bool |
||
80 | |||
81 | /** |
||
82 | * {@inheritdoc} |
||
83 | */ |
||
84 | public function isAuthorized(): bool |
||
92 | |||
93 | /** |
||
94 | * {@inheritdoc} |
||
95 | */ |
||
96 | public function getMessage(): string |
||
104 | |||
105 | /** |
||
106 | * Checks if given string is valid json. |
||
107 | * |
||
108 | * @param string $string |
||
109 | * |
||
110 | * @return bool |
||
111 | */ |
||
112 | private function isValidJson($string): bool |
||
122 | } |
||
123 |