1 | <?php |
||
27 | class JsonApiViewListener |
||
28 | { |
||
29 | /** |
||
30 | * Object-handlers |
||
31 | * |
||
32 | * @var ObjectHandlerInterface[] |
||
33 | */ |
||
34 | protected $objectHandlers = []; |
||
35 | |||
36 | /** |
||
37 | * Add object-handler |
||
38 | * |
||
39 | * @param ObjectHandlerInterface $handler |
||
40 | */ |
||
41 | 2 | public function addObjectHandler(ObjectHandlerInterface $handler) |
|
48 | |||
49 | /** |
||
50 | * On Kernel View event handler |
||
51 | * |
||
52 | * @param GetResponseForControllerResultEvent $event |
||
53 | */ |
||
54 | 8 | public function onKernelView(GetResponseForControllerResultEvent $event) |
|
77 | |||
78 | /** |
||
79 | * Handle Json API view |
||
80 | * |
||
81 | * @param AbstractJsonApiView $view |
||
82 | * @return Response |
||
83 | */ |
||
84 | 5 | protected function handleView(AbstractJsonApiView $view): Response |
|
100 | |||
101 | /** |
||
102 | * Handle document Json API view |
||
103 | * |
||
104 | * @param JsonApiDocumentView $view |
||
105 | * @return Response |
||
106 | */ |
||
107 | 1 | protected function handleDocumentView(JsonApiDocumentView $view) |
|
115 | |||
116 | /** |
||
117 | * Handle single object Json API view |
||
118 | * |
||
119 | * @param JsonApiObjectView $view |
||
120 | * @return Response |
||
121 | */ |
||
122 | 2 | protected function handleObjectView(JsonApiObjectView $view): Response |
|
130 | |||
131 | /** |
||
132 | * Handle object-iterator |
||
133 | * |
||
134 | * @param JsonApiIteratorView $view |
||
135 | * @return Response |
||
136 | */ |
||
137 | 1 | protected function handleIteratorView(JsonApiIteratorView $view): Response |
|
154 | |||
155 | /** |
||
156 | * Handle response data besides of the document itself |
||
157 | * |
||
158 | * @param Response $response |
||
159 | * @param AbstractJsonApiView $view |
||
160 | */ |
||
161 | 3 | protected function handleResponseExtras(Response $response, AbstractJsonApiView $view) |
|
166 | |||
167 | /** |
||
168 | * Handle object |
||
169 | * |
||
170 | * @param $object |
||
171 | * @return ResourceObject |
||
172 | */ |
||
173 | 3 | protected function handleObject($object): ResourceObject |
|
183 | |||
184 | /** |
||
185 | * Handle single resource object |
||
186 | * |
||
187 | * @param ResourceObject $resource |
||
188 | * @return Response |
||
189 | */ |
||
190 | 2 | protected function handleResource(ResourceObject $resource): Response |
|
197 | |||
198 | /** |
||
199 | * Handle error |
||
200 | * |
||
201 | * @param ErrorObject $error |
||
202 | * @return Response |
||
203 | */ |
||
204 | protected function handleError(ErrorObject $error): Response |
||
212 | |||
213 | /** |
||
214 | * Create response |
||
215 | * |
||
216 | * @param AbstractDocument $document |
||
217 | * @return Response |
||
218 | */ |
||
219 | 5 | protected function createResponse(AbstractDocument $document): Response |
|
228 | |||
229 | /** |
||
230 | * Encode object into a json-string |
||
231 | * |
||
232 | * @param mixed $object |
||
233 | * @return string |
||
234 | * @throws \LogicException |
||
235 | */ |
||
236 | 5 | protected function encode($object): string |
|
246 | } |