1 | <?php |
||
12 | abstract class AbstractEndpointController implements |
||
13 | DatabaseAwareInterface |
||
14 | { |
||
15 | use DatabaseAwareTrait; |
||
16 | |||
17 | /** |
||
18 | * Contains the repository used for interfacing with the database |
||
19 | * |
||
20 | * @var \Ps2alerts\Api\Repository\AbstractEndpointRepository |
||
21 | */ |
||
22 | protected $repository; |
||
23 | |||
24 | /** |
||
25 | * Stores the status code |
||
26 | * |
||
27 | * @var integer |
||
28 | */ |
||
29 | protected $statusCode = 200; |
||
30 | |||
31 | /** |
||
32 | * Holds Fractal |
||
33 | * |
||
34 | * @var \League\Fractal\Manager |
||
35 | */ |
||
36 | protected $fractal; |
||
37 | |||
38 | /** |
||
39 | * Holds the transformer we're going to use |
||
40 | * |
||
41 | * @var mixed|\Leage\Fractal\TransformerAbstract |
||
42 | */ |
||
43 | protected $transformer; |
||
44 | |||
45 | const CODE_WRONG_ARGS = 'API-MALFORMED-REQUEST'; |
||
46 | const CODE_NOT_FOUND = 'API-NOT-FOUND'; |
||
47 | const CODE_INTERNAL_ERROR = 'API-DOH'; |
||
48 | const CODE_UNAUTHORIZED = 'API-UNAUTHORIZED'; |
||
49 | const CODE_FORBIDDEN = 'API-DENIED'; |
||
50 | const CODE_EMPTY = 'API-EMPTY'; |
||
51 | |||
52 | /** |
||
53 | * Getter for statusCode |
||
54 | * |
||
55 | * @return int |
||
56 | */ |
||
57 | public function getStatusCode() |
||
61 | |||
62 | /** |
||
63 | * Setter for statusCode |
||
64 | * |
||
65 | * @param int $statusCode Value to set |
||
66 | * |
||
67 | * @return self |
||
68 | */ |
||
69 | public function setStatusCode($statusCode) |
||
74 | |||
75 | /** |
||
76 | * Master function to split out appropiate calls |
||
77 | * |
||
78 | * @param string $kind The kind of data we wish to return |
||
79 | * @param array $data The data itself |
||
80 | * @param \League\Fractal\TransformerAbstract $callback The transformer class to call |
||
81 | * @param \Symfony\Component\HttpFoundation\Request $request The request itself |
||
82 | * @param \Symfony\Component\HttpFoundation\Response $response The response object to eventually call |
||
83 | * |
||
84 | * @return \Symfony\Component\HttpFoundation\Response |
||
85 | */ |
||
86 | protected function respond($kind, $data, $callback, Request $request, Response $response) |
||
99 | |||
100 | /** |
||
101 | * Builds an item response in Fractal then hands off to the responder |
||
102 | * |
||
103 | * @param array $item The item to transform |
||
104 | * @param \League\Fractal\TransformerAbstract $transformer The Transformer to pass through to Fractal |
||
105 | * @param \Symfony\Component\HttpFoundation\Response $response The client's response |
||
106 | * |
||
107 | * @return array |
||
108 | */ |
||
109 | protected function respondWithItem($item, $transformer, Response $response) |
||
113 | |||
114 | /** |
||
115 | * Creates the item array and returns it hence it came. |
||
116 | * |
||
117 | * @param array $item The data to parse |
||
118 | * @param \League\Fractal\TransformerAbstract $transformer |
||
119 | * |
||
120 | * @return array |
||
121 | */ |
||
122 | public function createItem($item, $transformer) |
||
129 | |||
130 | /** |
||
131 | * Builds a collection of items from Fractal then hands off to the responder |
||
132 | * |
||
133 | * @param array $collection The collection to transform |
||
134 | * @param \League\Fractal\TransformerAbstract $transformer The Transformer to pass through to Fractal |
||
135 | * @param \Symfony\Component\HttpFoundation\Response $response The client's response |
||
136 | * |
||
137 | * @return array |
||
138 | */ |
||
139 | protected function respondWithCollection($collection, $transformer, Response $response) |
||
143 | |||
144 | /** |
||
145 | * Creates a collection array and sends it back to hence it came. |
||
146 | * |
||
147 | * @param array $collection |
||
148 | * @param \League\Fractal\TransformerAbstract $transformer |
||
149 | * |
||
150 | * @return array |
||
151 | */ |
||
152 | public function createCollection($collection, $transformer) |
||
159 | |||
160 | /** |
||
161 | * The final step where the formatted array is now sent back as a response in JSON form |
||
162 | * |
||
163 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
164 | * @param array $array |
||
165 | * |
||
166 | * @return \Symfony\Component\HttpFoundation\Response |
||
167 | */ |
||
168 | protected function respondWithArray(Response $response, array $array) |
||
177 | |||
178 | /** |
||
179 | * Responds gracefully with an error. |
||
180 | * |
||
181 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
182 | * @param string $message Response message to put in the error |
||
183 | * @param int $errorCode Error code to set |
||
184 | * |
||
185 | * @return array |
||
186 | */ |
||
187 | protected function respondWithError(Response $response, $message, $errorCode) |
||
205 | |||
206 | /** |
||
207 | * Generates a response with a 404 HTTP error and a given message. |
||
208 | * |
||
209 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
210 | * @param string $message |
||
211 | * |
||
212 | * @return void |
||
213 | */ |
||
214 | public function errorEmpty(Response $response, $message = 'No data / Empty') |
||
219 | |||
220 | /** |
||
221 | * Generates a Response with a 403 HTTP header and a given message. |
||
222 | * |
||
223 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
224 | * @param string $message |
||
225 | * |
||
226 | * @return void |
||
227 | */ |
||
228 | public function errorForbidden(Response $response, $message = 'Forbidden') |
||
233 | |||
234 | /** |
||
235 | * Generates a Response with a 500 HTTP header and a given message. |
||
236 | * |
||
237 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
238 | * @param string $message |
||
239 | * |
||
240 | * @return void |
||
241 | */ |
||
242 | public function errorInternalError(Response $response, $message = 'Internal Error') |
||
247 | |||
248 | /** |
||
249 | * Generates a Response with a 404 HTTP header and a given message. |
||
250 | * |
||
251 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
252 | * @param string $message |
||
253 | * |
||
254 | * @return void |
||
255 | */ |
||
256 | public function errorNotFound(Response $response, $message = 'Resource Not Found') |
||
261 | |||
262 | /** |
||
263 | * Generates a Response with a 401 HTTP header and a given message. |
||
264 | * |
||
265 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
266 | * @param string $message |
||
267 | * |
||
268 | * @return void |
||
269 | */ |
||
270 | public function errorUnauthorized(Response $response, $message = 'Unauthorized') |
||
275 | |||
276 | /** |
||
277 | * Generates a Response with a 400 HTTP header and a given message. |
||
278 | * |
||
279 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
280 | * @param string $message |
||
281 | * |
||
282 | * @return \Symfony\Component\HttpFoundation\Response |
||
283 | */ |
||
284 | public function errorWrongArgs(Response $response, $message = 'Wrong Arguments') |
||
289 | |||
290 | /** |
||
291 | * Reads any requested includes and adds them to the item / collection |
||
292 | * |
||
293 | * @param Symfony\Component\HttpFoundation\Request $request |
||
294 | * |
||
295 | * @return void |
||
296 | */ |
||
297 | public function getIncludesFromRequest(Request $request) |
||
305 | } |
||
306 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: