1 | <?php |
||
15 | abstract class AbstractEndpointController implements |
||
16 | ConfigAwareInterface, |
||
17 | DatabaseAwareInterface |
||
18 | { |
||
19 | use ConfigAwareTrait; |
||
20 | use DatabaseAwareTrait; |
||
21 | |||
22 | /** |
||
23 | * Contains the repository used for interfacing with the database |
||
24 | * |
||
25 | * @var \Ps2alerts\Api\Repository\AbstractEndpointRepository |
||
26 | */ |
||
27 | protected $repository; |
||
28 | |||
29 | /** |
||
30 | * Stores the status code |
||
31 | * |
||
32 | * @var integer |
||
33 | */ |
||
34 | protected $statusCode = 200; |
||
35 | |||
36 | /** |
||
37 | * Holds Fractal |
||
38 | * |
||
39 | * @var \League\Fractal\Manager |
||
40 | */ |
||
41 | protected $fractal; |
||
42 | |||
43 | /** |
||
44 | * Holds the transformer we're going to use |
||
45 | * |
||
46 | * @var mixed|\Leage\Fractal\TransformerAbstract |
||
47 | */ |
||
48 | protected $transformer; |
||
49 | |||
50 | const CODE_WRONG_ARGS = 'API-MALFORMED-REQUEST'; |
||
51 | const CODE_NOT_FOUND = 'API-NOT-FOUND'; |
||
52 | const CODE_INTERNAL_ERROR = 'API-DOH'; |
||
53 | const CODE_UNAUTHORIZED = 'API-UNAUTHORIZED'; |
||
54 | const CODE_FORBIDDEN = 'API-DENIED'; |
||
55 | const CODE_EMPTY = 'API-EMPTY'; |
||
56 | |||
57 | /** |
||
58 | * Getter for statusCode |
||
59 | * |
||
60 | * @return int |
||
61 | */ |
||
62 | public function getStatusCode() |
||
66 | |||
67 | /** |
||
68 | * Setter for statusCode |
||
69 | * |
||
70 | * @param int $statusCode Value to set |
||
71 | * |
||
72 | * @return self |
||
73 | */ |
||
74 | public function setStatusCode($statusCode) |
||
79 | |||
80 | /** |
||
81 | * Master function to split out appropiate calls |
||
82 | * |
||
83 | * @param string $kind The kind of data we wish to return |
||
84 | * @param array $data The data itself |
||
85 | * @param \League\Fractal\TransformerAbstract $callback The transformer class to call |
||
86 | * @param \Symfony\Component\HttpFoundation\Request $request The request itself |
||
87 | * @param \Symfony\Component\HttpFoundation\Response $response The response object to eventually call |
||
88 | * |
||
89 | * @return \Symfony\Component\HttpFoundation\Response |
||
90 | */ |
||
91 | protected function respond($kind, $data, $callback, Request $request, Response $response) |
||
104 | |||
105 | /** |
||
106 | * Builds an item response in Fractal then hands off to the responder |
||
107 | * |
||
108 | * @param array $item The item to transform |
||
109 | * @param \League\Fractal\TransformerAbstract $transformer The Transformer to pass through to Fractal |
||
110 | * @param \Symfony\Component\HttpFoundation\Response $response The client's response |
||
111 | * |
||
112 | * @return array |
||
113 | */ |
||
114 | protected function respondWithItem($item, $transformer, Response $response) |
||
118 | |||
119 | /** |
||
120 | * Creates the item array and returns it hence it came. |
||
121 | * |
||
122 | * @param array $item The data to parse |
||
123 | * @param \League\Fractal\TransformerAbstract $transformer |
||
124 | * |
||
125 | * @return array |
||
126 | */ |
||
127 | public function createItem($item, $transformer) |
||
134 | |||
135 | /** |
||
136 | * Builds a collection of items from Fractal then hands off to the responder |
||
137 | * |
||
138 | * @param array $collection The collection to transform |
||
139 | * @param \League\Fractal\TransformerAbstract $transformer The Transformer to pass through to Fractal |
||
140 | * @param \Symfony\Component\HttpFoundation\Response $response The client's response |
||
141 | * |
||
142 | * @return array |
||
143 | */ |
||
144 | protected function respondWithCollection($collection, $transformer, Response $response) |
||
148 | |||
149 | /** |
||
150 | * Creates a collection array and sends it back to hence it came. |
||
151 | * |
||
152 | * @param array $collection |
||
153 | * @param \League\Fractal\TransformerAbstract $transformer |
||
154 | * |
||
155 | * @return array |
||
156 | */ |
||
157 | public function createCollection($collection, $transformer) |
||
164 | |||
165 | /** |
||
166 | * The final step where the formatted array is now sent back as a response in JSON form |
||
167 | * |
||
168 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
169 | * @param array $array |
||
170 | * |
||
171 | * @return \Symfony\Component\HttpFoundation\Response |
||
172 | */ |
||
173 | protected function respondWithArray(Response $response, array $array) |
||
182 | |||
183 | /** |
||
184 | * Responds gracefully with an error. |
||
185 | * |
||
186 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
187 | * @param string $message Response message to put in the error |
||
188 | * @param int $errorCode Error code to set |
||
189 | * |
||
190 | * @return array |
||
191 | */ |
||
192 | protected function respondWithError(Response $response, $message, $errorCode) |
||
210 | |||
211 | /** |
||
212 | * Generates a response with a 404 HTTP error and a given message. |
||
213 | * |
||
214 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
215 | * @param string $message |
||
216 | * |
||
217 | * @return void |
||
218 | */ |
||
219 | public function errorEmpty(Response $response, $message = 'No data / Empty') |
||
224 | |||
225 | /** |
||
226 | * Generates a Response with a 403 HTTP header and a given message. |
||
227 | * |
||
228 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
229 | * @param string $message |
||
230 | * |
||
231 | * @return void |
||
232 | */ |
||
233 | public function errorForbidden(Response $response, $message = 'Forbidden') |
||
238 | |||
239 | /** |
||
240 | * Generates a Response with a 500 HTTP header and a given message. |
||
241 | * |
||
242 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
243 | * @param string $message |
||
244 | * |
||
245 | * @return void |
||
246 | */ |
||
247 | public function errorInternalError(Response $response, $message = 'Internal Error') |
||
252 | |||
253 | /** |
||
254 | * Generates a Response with a 404 HTTP header and a given message. |
||
255 | * |
||
256 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
257 | * @param string $message |
||
258 | * |
||
259 | * @return void |
||
260 | */ |
||
261 | public function errorNotFound(Response $response, $message = 'Resource Not Found') |
||
266 | |||
267 | /** |
||
268 | * Generates a Response with a 401 HTTP header and a given message. |
||
269 | * |
||
270 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
271 | * @param string $message |
||
272 | * |
||
273 | * @return void |
||
274 | */ |
||
275 | public function errorUnauthorized(Response $response, $message = 'Unauthorized') |
||
280 | |||
281 | /** |
||
282 | * Generates a Response with a 400 HTTP header and a given message. |
||
283 | * |
||
284 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
285 | * @param string $message |
||
286 | * |
||
287 | * @return \Symfony\Component\HttpFoundation\Response |
||
288 | */ |
||
289 | public function errorWrongArgs(Response $response, $message = 'Wrong Arguments') |
||
294 | |||
295 | /** |
||
296 | * Reads any requested includes and adds them to the item / collection |
||
297 | * |
||
298 | * @param Symfony\Component\HttpFoundation\Request $request |
||
299 | * |
||
300 | * @return void |
||
301 | */ |
||
302 | public function getIncludesFromRequest(Request $request) |
||
310 | |||
311 | /** |
||
312 | * Gets the Server or Zone filters and runs a check to make sure the request validates. Also formats the list |
||
313 | * correctly for inclusion in query strings. |
||
314 | * |
||
315 | * @param string $queryString |
||
316 | * @param string $mode |
||
317 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
318 | * |
||
319 | * @return string |
||
320 | */ |
||
321 | public function getFiltersFromQueryString($queryString, $mode, $response) |
||
366 | } |
||
367 |
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: