1 | <?php |
||
19 | class RestController extends Controller |
||
20 | { |
||
21 | |||
22 | const MIME_TYPE_JSON = 'application/json'; |
||
23 | |||
24 | 36 | public function respond(AbstractApiResponse $apiResponse): Response |
|
33 | |||
34 | /** |
||
35 | * Process form |
||
36 | * @param Request $request |
||
37 | * @param FormInterface $form |
||
38 | */ |
||
39 | 13 | protected function processForm(Request $request, FormInterface $form) |
|
46 | |||
47 | /** {@inheritDoc} */ |
||
48 | 10 | protected function createFormBuilder($data = null, array $options = []): FormBuilder |
|
54 | |||
55 | /** |
||
56 | * Create collection api response with total, limit and offset parameters |
||
57 | * @param integer|null $limit |
||
58 | * @param integer|null $offset |
||
59 | */ |
||
60 | 3 | protected function createCompleteCollectionResponse(AbstractRepository $repository, $limit, $offset): CollectionApiResponse |
|
61 | { |
||
62 | 3 | $limit = (int) filter_var($limit, FILTER_VALIDATE_INT); |
|
63 | 3 | $offset = (int) filter_var($offset, FILTER_VALIDATE_INT); |
|
64 | |||
65 | 3 | $entities = $repository->findAllWithLimitAndOffset($limit, $offset); |
|
66 | 3 | $entitiesQuantity = $repository->countAll(); |
|
67 | |||
68 | 3 | $response = new CollectionApiResponse($entities, Response::HTTP_OK, $entitiesQuantity, $limit, $offset); |
|
69 | |||
70 | 3 | return $response; |
|
71 | } |
||
72 | |||
73 | 36 | private function setLocation(Response $response, AbstractApiResponse $apiResponse) |
|
79 | |||
80 | 36 | private function setContentType(AbstractApiResponse $apiResponse, Response $response) |
|
86 | } |
||
87 |