1 | <?php |
||
21 | class Response extends AbstractResponse |
||
22 | { |
||
23 | /** |
||
24 | * @param array $array |
||
25 | * @param array $headers |
||
26 | * @return ResponseFactory |
||
27 | */ |
||
28 | public function withArray(array $array, array $headers = []) |
||
32 | |||
33 | /** |
||
34 | * Respond with a paginator, and a transformer. |
||
35 | * |
||
36 | * @param LengthAwarePaginator $paginator |
||
37 | * @param callable|\League\Fractal\TransformerAbstract $transformer |
||
38 | * @param string $resourceKey |
||
39 | * @param array $meta |
||
40 | * @return ResponseFactory |
||
41 | */ |
||
42 | 1 | public function withPaginator(LengthAwarePaginator $paginator, $transformer, $resourceKey = null, $meta = []) |
|
|
|||
43 | { |
||
44 | 1 | $queryParams = array_diff_key($_GET, array_flip(['page'])); |
|
45 | 1 | $paginator->appends($queryParams); |
|
46 | |||
47 | 1 | $resource = new Collection($paginator->items(), $transformer, $resourceKey); |
|
48 | 1 | $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); |
|
49 | |||
50 | 1 | foreach ($meta as $metaKey => $metaValue) { |
|
51 | 1 | $resource->setMetaValue($metaKey, $metaValue); |
|
52 | 1 | } |
|
53 | |||
54 | 1 | $rootScope = $this->manager->createData($resource); |
|
55 | |||
56 | 1 | return $this->withArray($rootScope->toArray()); |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Generates a Response with a 400 HTTP header and a given message from validator |
||
61 | * |
||
62 | * @param Validator $validator |
||
63 | * @return ResponseFactory |
||
64 | */ |
||
65 | 1 | public function errorWrongArgsValidator(Validator $validator) |
|
69 | } |
||
70 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: