1 | <?php |
||
11 | abstract class CrudServiceRestResourceController extends AbstractRestResourceController |
||
12 | { |
||
13 | /** |
||
14 | * {@inheritdoc} |
||
15 | */ |
||
16 | 6 | protected function listEntities(int $page = 1, int $perPage = 50) |
|
20 | |||
21 | /** |
||
22 | * {@inheritdoc} |
||
23 | */ |
||
24 | 56 | protected function fetchEntity($id) |
|
25 | { |
||
26 | 56 | $entity = $this->getService()->find($id); |
|
27 | 56 | if (null === $entity) { |
|
28 | throw new NotFoundHttpException(); |
||
29 | } |
||
30 | |||
31 | 56 | return $entity; |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | 10 | protected function createEntity($entity) |
|
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | 10 | protected function updateEntity($entity) |
|
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | 2 | protected function removeEntity($entity) |
|
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | 6 | protected function listSubresource($entity, string $property, int $page = 1, int $perPage = 50) |
|
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | 2 | protected function createAssociation($parent, string $subresource) |
|
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | 2 | protected function createSubResource($parent, $subresource, $entity) |
|
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | 12 | protected function addAssociation($parent, string $subresource, $subId) |
|
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | 12 | protected function removeAssociation($parent, string $subresource, $subId = null) |
|
97 | |||
98 | 72 | protected function getServiceId() |
|
102 | |||
103 | /** |
||
104 | * @return CrudServiceInterface |
||
105 | */ |
||
106 | abstract protected function getService(); |
||
107 | } |
||
108 |