1 | <?php |
||
15 | final class ResponseFactory |
||
16 | { |
||
17 | const CODE_WRONG_ARGS = 'GEN-ARGUMENTS'; |
||
18 | |||
19 | const CODE_NOT_FOUND = 'GEN-NOTFOUND'; |
||
20 | |||
21 | const CODE_INTERNAL_ERROR = 'GEN-SERVERERROR'; |
||
22 | |||
23 | const CODE_UNAUTHORIZED = 'GEN-UNAUTHORIZED'; |
||
24 | |||
25 | const CODE_FORBIDDEN = 'GEN-FORBIDDEN'; |
||
26 | |||
27 | /** |
||
28 | * @var Manager |
||
29 | */ |
||
30 | private $fractal; |
||
31 | |||
32 | /** |
||
33 | * @var PaginatorInterface |
||
34 | */ |
||
35 | private $paginator; |
||
36 | |||
37 | /** |
||
38 | * @var CursorInterface |
||
39 | */ |
||
40 | private $cursor; |
||
41 | |||
42 | /** |
||
43 | * @param Manager $fractal |
||
44 | */ |
||
45 | public function __construct(Manager $fractal) |
||
49 | |||
50 | /** |
||
51 | * @return Manager |
||
52 | */ |
||
53 | public function getFractal() |
||
57 | |||
58 | /** |
||
59 | * @param mixed $item |
||
60 | * @param $callback |
||
61 | * |
||
62 | * @return JsonResponse |
||
63 | */ |
||
64 | public function createWithItem($item, $callback) |
||
71 | |||
72 | /** |
||
73 | * @param mixed $collection |
||
74 | * @param $callback |
||
75 | * |
||
76 | * @return JsonResponse |
||
77 | */ |
||
78 | public function createWithCollection($collection, $callback) |
||
90 | |||
91 | /** |
||
92 | * @param PaginatorInterface $paginator |
||
93 | * |
||
94 | * @return ResponseFactory |
||
95 | */ |
||
96 | public function withPaginator(PaginatorInterface $paginator) |
||
103 | |||
104 | /** |
||
105 | * @param CursorInterface $cursor |
||
106 | * |
||
107 | * @return ResponseFactory |
||
108 | */ |
||
109 | public function withCursor(CursorInterface $cursor) |
||
116 | |||
117 | /** |
||
118 | * @param array $array |
||
119 | * @param int $statusCode |
||
120 | * @param array $headers |
||
121 | * |
||
122 | * @return JsonResponse |
||
123 | */ |
||
124 | public function createWithArray(array $array, $statusCode = 200, array $headers = []) |
||
128 | |||
129 | /** |
||
130 | * @param string $message |
||
131 | * @param int $statusCode |
||
132 | * @param string $errorCode |
||
133 | * |
||
134 | * @return JsonResponse |
||
135 | */ |
||
136 | public function createWithError($message, $statusCode, $errorCode) |
||
153 | |||
154 | /** |
||
155 | * Generates a Response with a 403 HTTP header and a given message. |
||
156 | * |
||
157 | * @param string $message |
||
158 | * |
||
159 | * @return JsonResponse |
||
160 | */ |
||
161 | public function createForbidden($message = 'Forbidden') |
||
165 | |||
166 | /** |
||
167 | * Generates a Response with a 500 HTTP header and a given message. |
||
168 | * |
||
169 | * @param string $message |
||
170 | * |
||
171 | * @return JsonResponse |
||
172 | */ |
||
173 | public function createInternalError($message = 'Internal Error') |
||
177 | |||
178 | /** |
||
179 | * Generates a Response with a 404 HTTP header and a given message. |
||
180 | * |
||
181 | * @param string $message |
||
182 | * |
||
183 | * @return JsonResponse |
||
184 | */ |
||
185 | public function createNotFound($message = 'Resource Not Found') |
||
189 | |||
190 | /** |
||
191 | * Generates a Response with a 401 HTTP header and a given message. |
||
192 | * |
||
193 | * @param string $message |
||
194 | * |
||
195 | * @return JsonResponse |
||
196 | */ |
||
197 | public function createUnauthorized($message = 'Unauthorized') |
||
201 | |||
202 | /** |
||
203 | * Generates a Response with a 400 HTTP header and a given message. |
||
204 | * |
||
205 | * @param string $message |
||
206 | * |
||
207 | * @return JsonResponse |
||
208 | */ |
||
209 | public function createWrongArgs($message = 'Wrong Arguments') |
||
213 | } |
||
214 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.