1 | <?php |
||
20 | trait RestApiControllerTrait |
||
21 | { |
||
22 | use ControllerTrait; |
||
23 | |||
24 | /** |
||
25 | * Create a JsonResponse with given data, if object given, it will be serialize |
||
26 | * with registered serializer. |
||
27 | * |
||
28 | * @param mixed $data |
||
29 | * @param string $scope |
||
30 | * @param int $status |
||
31 | * |
||
32 | * @return Response |
||
33 | */ |
||
34 | protected function createJsonResponse($data = null, $scope = null, $status = 200) |
||
50 | |||
51 | /** |
||
52 | * build and return a non content response. |
||
53 | * |
||
54 | * @return JsonResponse |
||
55 | */ |
||
56 | protected function createJsonNoContentResponse() |
||
63 | |||
64 | /** |
||
65 | * create and returns a 400 Bad Request response. |
||
66 | * |
||
67 | * @param array $errors |
||
68 | * |
||
69 | * @return JsonResponse |
||
70 | */ |
||
71 | protected function createJsonBadRequestResponse(array $errors = array()) |
||
94 | |||
95 | /** |
||
96 | * Retrieve given request data depending on its content type. |
||
97 | * |
||
98 | * @param Request $request |
||
99 | * @param string $inflection optional inflector to tuse on parameter keys |
||
100 | * |
||
101 | * @return array |
||
102 | * |
||
103 | * @throws HttpException if JSON content-type and invalid JSON data |
||
104 | */ |
||
105 | protected function getRequestData(Request $request, $inflection = 'camelize') |
||
135 | |||
136 | /** |
||
137 | * Custom method for form submission to handle http method bugs, and extra fields |
||
138 | * error options. |
||
139 | * |
||
140 | * @param Request $request |
||
141 | * @param FormInterface $form |
||
142 | * |
||
143 | * @throws HttpException if invalid json data |
||
144 | * @throws ValidationException if invalid form |
||
145 | */ |
||
146 | protected function assertSubmitedFormIsValid(Request $request, FormInterface $form) |
||
160 | |||
161 | /** |
||
162 | * verify if intention on given resource (request if undefined) is granted |
||
163 | * |
||
164 | * @param string $intention |
||
165 | * @param mixed $resource |
||
166 | * |
||
167 | * @throws AccessDeniedHttpException if denied |
||
168 | */ |
||
169 | protected function assertIsGrantedOr403($intention, $resource = null) |
||
179 | |||
180 | /** |
||
181 | * Forwarding action which can proxy other controllers / methods, in cases |
||
182 | * of some protocols isn't supported by clients |
||
183 | * |
||
184 | * Routing has to provide 2 options keys : |
||
185 | * @example |
||
186 | * route_name: |
||
187 | * path: ....... |
||
188 | * .... |
||
189 | * options: |
||
190 | * forward: |
||
191 | * controller: MajoraNamespaceBundle:MajoraEntityApi:link |
||
192 | * method: LINK # GET by default here |
||
193 | * |
||
194 | * @param Request $request |
||
195 | * |
||
196 | * @return Response |
||
197 | */ |
||
198 | public function forwardAction(Request $request) |
||
222 | } |
||
223 |