1 | <?php |
||
13 | abstract class Controller extends BaseController |
||
14 | { |
||
15 | use QueryHelperTrait, ErrorResponsesTrait; |
||
16 | |||
17 | protected $statusCode = 200; |
||
18 | protected $fractal; |
||
19 | |||
20 | public function __construct() |
||
21 | { |
||
22 | $this->fractal = App::make(Fractal::class); |
||
23 | |||
24 | $this->parseIncludes(); |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * Parses includes from either the header or query string. |
||
29 | * |
||
30 | * @return mixed |
||
31 | */ |
||
32 | protected function parseIncludes() |
||
33 | { |
||
34 | if (Input::header('include')) { |
||
35 | return $this->fractal->parseIncludes(Input::header('include')); |
||
36 | } |
||
37 | |||
38 | if (Input::get('include')) { |
||
39 | return $this->fractal->parseIncludes(Input::get('include')); |
||
40 | } |
||
41 | |||
42 | return null; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Returns the current status code. |
||
47 | * |
||
48 | * @return int |
||
49 | */ |
||
50 | protected function getStatusCode() |
||
54 | |||
55 | /** |
||
56 | * Sets the current status code. |
||
57 | * |
||
58 | * @param $statusCode |
||
59 | * @return $this |
||
60 | */ |
||
61 | protected function setStatusCode($statusCode) |
||
67 | |||
68 | /** |
||
69 | * Eager load anything that needs to be included |
||
70 | * |
||
71 | * @param Eloquent Builder |
||
72 | * @return $builder |
||
|
|||
73 | */ |
||
74 | private function prepareBuilder($builder) |
||
82 | |||
83 | /** |
||
84 | * Returns a json response that contains the specified resource |
||
85 | * passed through fractal and optionally a transformer. |
||
86 | * |
||
87 | * @param $item |
||
88 | * @param null $callback |
||
89 | * @param null $resourceKey |
||
90 | * @return \Illuminate\Http\JsonResponse |
||
91 | */ |
||
92 | protected function respondWithItem($item, $callback = null, $resourceKey = false) |
||
103 | |||
104 | /** |
||
105 | * Returns a json response that indicates the resource was successfully created also |
||
106 | * returns the resource passed through fractal and optionally a transformer. |
||
107 | * |
||
108 | * @param $item |
||
109 | * @param null $callback |
||
110 | * @param null $resourceKey |
||
111 | * @return \Illuminate\Http\JsonResponse |
||
112 | */ |
||
113 | protected function respondWithItemCreated($item, $callback = null, $resourceKey = false) |
||
120 | |||
121 | /** |
||
122 | * Returns a json response that contains the specified collection |
||
123 | * passed through fractal and optionally a transformer. |
||
124 | * |
||
125 | * @param $collection |
||
126 | * @param $callback |
||
127 | * @param null $resourceKey |
||
128 | * @return \Illuminate\Http\JsonResponse |
||
129 | */ |
||
130 | protected function respondWithCollection($collection, $callback, $resourceKey = false) |
||
136 | |||
137 | /** |
||
138 | * Returns a json response that contains the specified paginated collection |
||
139 | * passed through fractal and optionally a transformer. |
||
140 | * |
||
141 | * @param $builder |
||
142 | * @param $callback |
||
143 | * @param int $perPage |
||
144 | * @param null $resourceKey |
||
145 | * @return \Illuminate\Http\JsonResponse |
||
146 | */ |
||
147 | protected function respondWithPaginatedCollection($builder = null, $perPage = 10, $resourceKey = null) |
||
160 | |||
161 | /** |
||
162 | * Returns an array of Query Parameters, not including pagination. |
||
163 | * |
||
164 | * @return array |
||
165 | */ |
||
166 | protected function getQueryParameters() |
||
170 | |||
171 | /** |
||
172 | * Returns a json response that contains the specified array, |
||
173 | * the current status code and optional headers. |
||
174 | * |
||
175 | * @param array $array |
||
176 | * @param array $headers |
||
177 | * @return \Illuminate\Http\JsonResponse |
||
178 | */ |
||
179 | protected function respondWithArray(array $array, array $headers = []) |
||
183 | |||
184 | /** |
||
185 | * Returns a response that indicates success but no content returned. |
||
186 | * |
||
187 | * @return \Illuminate\Http\Response |
||
188 | */ |
||
189 | protected function respondWithNoContent() |
||
193 | } |
||
194 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.