1 | <?php |
||
27 | class JsonApiViewListener |
||
28 | { |
||
29 | /** |
||
30 | * Document builder |
||
31 | * |
||
32 | * @var DocumentBuilder |
||
33 | */ |
||
34 | protected $documentBuilder; |
||
35 | |||
36 | /** |
||
37 | * JsonApiViewListener constructor. |
||
38 | * |
||
39 | * @param DocumentBuilder $builder |
||
40 | */ |
||
41 | 8 | public function __construct(DocumentBuilder $builder) |
|
45 | |||
46 | /** |
||
47 | * On Kernel View event handler |
||
48 | * |
||
49 | * @param GetResponseForControllerResultEvent $event |
||
50 | */ |
||
51 | 7 | public function onKernelView(GetResponseForControllerResultEvent $event) |
|
65 | |||
66 | /** |
||
67 | * Handle result |
||
68 | * |
||
69 | * @param mixed $result |
||
70 | * @return Response | null |
||
71 | */ |
||
72 | 6 | protected function handleResult($result) |
|
99 | |||
100 | /** |
||
101 | * Handle document Json API view |
||
102 | * |
||
103 | * @param JsonApiDocumentView $view |
||
104 | * @return Response |
||
105 | */ |
||
106 | 1 | protected function handleDocumentView(JsonApiDocumentView $view) |
|
114 | |||
115 | /** |
||
116 | * Handle a JSON-API view contains an object(s) for serialization |
||
117 | * |
||
118 | * @param AbstractJsonApiView $view |
||
119 | * @return Response |
||
120 | */ |
||
121 | 2 | protected function handleView(AbstractJsonApiView $view) |
|
129 | |||
130 | /** |
||
131 | * Handle response data besides of the document itself |
||
132 | * |
||
133 | * @param Response $response |
||
134 | * @param HttpAttributesAwareInterface $view |
||
135 | */ |
||
136 | 3 | protected function handleHttpAttributes(Response $response, HttpAttributesAwareInterface $view) |
|
141 | |||
142 | /** |
||
143 | * Handle single resource object |
||
144 | * |
||
145 | * @param ResourceObject $resource |
||
146 | * @return Response |
||
147 | */ |
||
148 | 1 | protected function handleResource(ResourceObject $resource): Response |
|
155 | |||
156 | /** |
||
157 | * Handle error |
||
158 | * |
||
159 | * @param ErrorObject $error |
||
160 | * @return Response |
||
161 | */ |
||
162 | 1 | protected function handleError(ErrorObject $error): Response |
|
170 | |||
171 | /** |
||
172 | * Create response |
||
173 | * |
||
174 | * @param AbstractDocument $document |
||
175 | * @return Response |
||
176 | */ |
||
177 | 6 | protected function createResponse(AbstractDocument $document): Response |
|
186 | |||
187 | /** |
||
188 | * Encode object into a json-string |
||
189 | * |
||
190 | * @param mixed $object |
||
191 | * @return string |
||
192 | * @throws \LogicException |
||
193 | */ |
||
194 | 6 | protected function encode($object): string |
|
204 | } |