1 | <?php |
||
29 | abstract class AbstractRestResourceController implements RestResourceControllerInterface |
||
30 | { |
||
31 | /** |
||
32 | * {@inheritdoc} |
||
33 | */ |
||
34 | 10 | public function listAction(Request $request) |
|
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | 14 | public function postAction(Request $request) |
|
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | 32 | public function getAction(Request $request, $id) |
|
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | 12 | public function putAction(Request $request, $id) |
|
116 | |||
117 | /** |
||
118 | * {@inheritdoc} |
||
119 | */ |
||
120 | 4 | public function deleteAction(Request $request, $id) |
|
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | 6 | public function listSubresourceAction(Request $request, $id, string $subresource) |
|
158 | |||
159 | /** |
||
160 | * {@inheritdoc} |
||
161 | */ |
||
162 | 4 | public function postSubresourceAction(Request $request, $id, string $subresource) |
|
185 | |||
186 | /** |
||
187 | * {@inheritdoc} |
||
188 | */ |
||
189 | 12 | public function putSubresourceAction(Request $request, $id, string $subresource, $subId) |
|
197 | |||
198 | /** |
||
199 | * {@inheritdoc} |
||
200 | */ |
||
201 | 12 | public function deleteSubresourceAction(Request $request, $id, string $subresource, $subId = null) |
|
209 | |||
210 | /** |
||
211 | * @param object $entity |
||
212 | * |
||
213 | * @return object |
||
214 | */ |
||
215 | 12 | protected function postProcessPostedEntity($entity) |
|
219 | |||
220 | /** |
||
221 | * @param object $entity |
||
222 | * |
||
223 | * @return object |
||
224 | */ |
||
225 | 10 | protected function postProcessPuttedEntity($entity) |
|
229 | |||
230 | /** |
||
231 | * @param object $parent |
||
232 | * @param string $subresource |
||
233 | * @param object $entity |
||
234 | * |
||
235 | * @return object |
||
236 | */ |
||
237 | 2 | protected function postProcessSubResourcePostedEntity($parent, $subresource, $entity) |
|
241 | |||
242 | 80 | protected function getEntityClass() |
|
246 | |||
247 | 2 | protected function getSubResourceEntityClass($subresource) |
|
254 | |||
255 | 80 | protected function getCurrentRequest() |
|
259 | |||
260 | 70 | protected function assertMethodGranted(string $methodName, $entity = null) |
|
267 | |||
268 | /** |
||
269 | * @param string $methodName |
||
270 | * @param object $entity |
||
271 | * @param string $subresource |
||
272 | */ |
||
273 | 30 | protected function assertSubResourceMethodGranted($methodName, $entity, string $subresource): void |
|
283 | |||
284 | /** |
||
285 | * @return ClassMetadata |
||
286 | */ |
||
287 | 80 | protected function getClassMetadata() |
|
295 | |||
296 | protected function resolveSubject($entity, $propertyPath) |
||
305 | |||
306 | /** |
||
307 | * @param Right $right |
||
308 | * @param object $entity |
||
309 | */ |
||
310 | 46 | protected function assertRightGranted(Right $right, $entity = null) |
|
320 | |||
321 | 62 | protected function parseIncludes(Request $request) |
|
337 | |||
338 | 46 | protected function denyAccessUnlessGranted($attributes, $object = null, $message = 'Access Denied.') |
|
344 | |||
345 | 2 | protected function parseConstraintViolations(ConstraintViolationListInterface $errors) |
|
359 | |||
360 | 12 | protected function addPaginationHeaders(Response $response, int $page, int $perPage, int $total) |
|
371 | |||
372 | /** |
||
373 | * @param int $page |
||
374 | * @param int $perPage |
||
375 | * |
||
376 | * @return Paginator|array |
||
377 | */ |
||
378 | abstract protected function listEntities(int $page = 1, int $perPage = 50); |
||
379 | |||
380 | /** |
||
381 | * @param int|string $id |
||
382 | * |
||
383 | * @return object |
||
384 | * |
||
385 | * @throws NotFoundHttpException Thrown if entity with the given id could not be found. |
||
386 | */ |
||
387 | abstract protected function fetchEntity($id); |
||
388 | |||
389 | /** |
||
390 | * @param object $entity |
||
391 | * |
||
392 | * @return object |
||
393 | */ |
||
394 | abstract protected function createEntity($entity); |
||
395 | |||
396 | /** |
||
397 | * @param object $entity |
||
398 | * |
||
399 | * @return object |
||
400 | * |
||
401 | * @throws NotFoundHttpException Thrown if entity with the given id could not be found. |
||
402 | */ |
||
403 | abstract protected function updateEntity($entity); |
||
404 | |||
405 | /** |
||
406 | * @param $entity |
||
407 | * |
||
408 | * @throws NotFoundHttpException Thrown if entity with the given id could not be found. |
||
409 | */ |
||
410 | abstract protected function removeEntity($entity); |
||
411 | |||
412 | /** |
||
413 | * @param object $entity |
||
414 | * @param string $property |
||
415 | * @param int $page |
||
416 | * @param int $perPage |
||
417 | * |
||
418 | * @return Paginator|array |
||
419 | */ |
||
420 | abstract protected function listSubresource($entity, string $property, int $page = 1, int $perPage = 50); |
||
421 | |||
422 | /** |
||
423 | * @param object $parent |
||
424 | * @param string $subresource |
||
425 | * |
||
426 | * @return object |
||
427 | */ |
||
428 | abstract protected function createAssociation($parent, string $subresource); |
||
429 | |||
430 | /** |
||
431 | * @param object $parent |
||
432 | * @param string $subresource |
||
433 | * @param object $entity |
||
434 | * |
||
435 | * @return object |
||
436 | */ |
||
437 | abstract protected function createSubResource($parent, $subresource, $entity); |
||
438 | |||
439 | /** |
||
440 | * @param object $parent |
||
441 | * @param string $subresource |
||
442 | * @param int|string $subId |
||
443 | * |
||
444 | * @return object |
||
445 | */ |
||
446 | abstract protected function addAssociation($parent, string $subresource, $subId); |
||
447 | |||
448 | /** |
||
449 | * @param object $parent |
||
450 | * @param string $subresource |
||
451 | * @param int|string|null $subId |
||
452 | * |
||
453 | * @return mixed |
||
454 | */ |
||
455 | abstract protected function removeAssociation($parent, string $subresource, $subId = null); |
||
456 | |||
457 | /** |
||
458 | * @return Normalizer |
||
459 | */ |
||
460 | abstract protected function getNormalizer(); |
||
461 | |||
462 | /** |
||
463 | * @return ValidatorInterface |
||
464 | */ |
||
465 | abstract protected function getValidator(); |
||
466 | |||
467 | /** |
||
468 | * @return RestRequestParser |
||
469 | */ |
||
470 | abstract protected function getRequestParser(); |
||
471 | |||
472 | /** |
||
473 | * @return RequestStack |
||
474 | */ |
||
475 | abstract protected function getRequestStack(); |
||
476 | |||
477 | /** |
||
478 | * @return MetadataFactoryInterface |
||
479 | */ |
||
480 | abstract protected function getMetadataFactory(); |
||
481 | |||
482 | /** |
||
483 | * @return PropertyAccessorInterface |
||
484 | */ |
||
485 | abstract protected function getPropertyAccessor(); |
||
486 | |||
487 | /** |
||
488 | * @return AuthorizationCheckerInterface |
||
489 | */ |
||
490 | abstract protected function getAuthorizationChecker(); |
||
491 | |||
492 | /** |
||
493 | * @return EntityManagerInterface |
||
494 | */ |
||
495 | abstract protected function getEntityManager(); |
||
496 | } |
||
497 |