1 | <?php |
||
30 | class JsonApiViewListener |
||
31 | { |
||
32 | /** |
||
33 | * Object-handlers |
||
34 | * |
||
35 | * @var ObjectHandlerInterface[] |
||
36 | */ |
||
37 | protected $objectHandlers = []; |
||
38 | |||
39 | /** |
||
40 | * Object-handlers resolved by supported class |
||
41 | * |
||
42 | * @var ObjectHandlerInterface[] |
||
43 | */ |
||
44 | protected $resolvedObjectHandlers = []; |
||
45 | |||
46 | /** |
||
47 | * Add object-handler |
||
48 | * |
||
49 | * @param ObjectHandlerInterface $handler |
||
50 | */ |
||
51 | 2 | public function addObjectHandler(ObjectHandlerInterface $handler) |
|
55 | |||
56 | /** |
||
57 | * On Kernel View event handler |
||
58 | * |
||
59 | * @param GetResponseForControllerResultEvent $event |
||
60 | */ |
||
61 | 10 | public function onKernelView(GetResponseForControllerResultEvent $event) |
|
75 | |||
76 | /** |
||
77 | * Handle result |
||
78 | * |
||
79 | * @param mixed $result |
||
80 | * @return Response | null |
||
81 | */ |
||
82 | 9 | protected function handleResult($result) |
|
114 | |||
115 | /** |
||
116 | * Handle document Json API view |
||
117 | * |
||
118 | * @param JsonApiDocumentView $view |
||
119 | * @return Response |
||
120 | */ |
||
121 | 1 | protected function handleDocumentView(JsonApiDocumentView $view) |
|
129 | |||
130 | /** |
||
131 | * Handle single object Json API view |
||
132 | * |
||
133 | * @param JsonApiObjectView $view |
||
134 | * @return Response |
||
135 | */ |
||
136 | 3 | protected function handleObjectView(JsonApiObjectView $view): Response |
|
151 | |||
152 | /** |
||
153 | * Handle a callback after a resource-object has created. |
||
154 | * |
||
155 | * @param AbstractJsonApiView $view |
||
156 | * @param ResourceObject $resource |
||
157 | */ |
||
158 | 4 | protected function handlePostResourceCallback(AbstractJsonApiView $view, ResourceObject $resource) |
|
165 | |||
166 | /** |
||
167 | * Handle supposed to be included to document resources |
||
168 | * |
||
169 | * @param AbstractDocument $document |
||
170 | * @param IncludedObjectsAwareInterface $view |
||
171 | */ |
||
172 | 4 | protected function handleIncludedResources(AbstractDocument $document, IncludedObjectsAwareInterface $view) |
|
180 | |||
181 | /** |
||
182 | * Handle object-iterator |
||
183 | * |
||
184 | * @param JsonApiIteratorView $view |
||
185 | * @return Response |
||
186 | */ |
||
187 | 2 | protected function handleIteratorView(JsonApiIteratorView $view): Response |
|
207 | |||
208 | /** |
||
209 | * Handle response data besides of the document itself |
||
210 | * |
||
211 | * @param Response $response |
||
212 | * @param HttpAttributesAwareInterface $view |
||
213 | */ |
||
214 | 5 | protected function handleHttpAttributes(Response $response, HttpAttributesAwareInterface $view) |
|
219 | |||
220 | /** |
||
221 | * Handle object |
||
222 | * |
||
223 | * @param $object |
||
224 | * @return ResourceObject |
||
225 | */ |
||
226 | 5 | protected function handleObject($object): ResourceObject |
|
236 | |||
237 | /** |
||
238 | * Get handler supports given class |
||
239 | * |
||
240 | * @param string $class |
||
241 | * @return ObjectHandlerInterface |
||
242 | * @throws \LogicException |
||
243 | */ |
||
244 | 3 | protected function getHandler(string $class): ObjectHandlerInterface |
|
259 | |||
260 | /** |
||
261 | * Handle single resource object |
||
262 | * |
||
263 | * @param ResourceObject $resource |
||
264 | * @return Response |
||
265 | */ |
||
266 | 1 | protected function handleResource(ResourceObject $resource): Response |
|
273 | |||
274 | /** |
||
275 | * Handle error |
||
276 | * |
||
277 | * @param ErrorObject $error |
||
278 | * @return Response |
||
279 | */ |
||
280 | 1 | protected function handleError(ErrorObject $error): Response |
|
288 | |||
289 | /** |
||
290 | * Create response |
||
291 | * |
||
292 | * @param AbstractDocument $document |
||
293 | * @return Response |
||
294 | */ |
||
295 | 8 | protected function createResponse(AbstractDocument $document): Response |
|
304 | |||
305 | /** |
||
306 | * Encode object into a json-string |
||
307 | * |
||
308 | * @param mixed $object |
||
309 | * @return string |
||
310 | * @throws \LogicException |
||
311 | */ |
||
312 | 8 | protected function encode($object): string |
|
322 | } |