1 | <?php namespace Neomerx\Limoncello\Http; |
||
36 | trait JsonApiTrait |
||
37 | { |
||
38 | /** |
||
39 | * If unrecognized parameters should be allowed in input parameters. |
||
40 | * |
||
41 | * @var bool |
||
42 | */ |
||
43 | protected $allowUnrecognizedParams = false; |
||
44 | |||
45 | /** |
||
46 | * A list of allowed include paths in input parameters. |
||
47 | * |
||
48 | * Empty array [] means clients are not allowed to specify include paths and 'null' means all paths are allowed. |
||
49 | * |
||
50 | * @var string[]|null |
||
51 | */ |
||
52 | protected $allowedIncludePaths = []; |
||
53 | |||
54 | /** |
||
55 | * A list of JSON API types which clients can sent field sets to. |
||
56 | * |
||
57 | * Possible values |
||
58 | * |
||
59 | * $allowedFieldSetTypes = null; // <-- for all types all fields are allowed |
||
60 | * |
||
61 | * $allowedFieldSetTypes = []; // <-- non of the types and fields are allowed |
||
62 | * |
||
63 | * $allowedFieldSetTypes = [ |
||
64 | * 'people' => null, // <-- all fields for 'people' are allowed |
||
65 | * 'comments' => [], // <-- no fields for 'comments' are allowed (all denied) |
||
66 | * 'posts' => ['title', 'body'], // <-- only 'title' and 'body' fields are allowed for 'posts' |
||
67 | * ]; |
||
68 | * |
||
69 | * @var array|null |
||
70 | */ |
||
71 | protected $allowedFieldSetTypes = null; |
||
72 | |||
73 | /** |
||
74 | * A list of allowed sort field names in input parameters. |
||
75 | * |
||
76 | * Empty array [] means clients are not allowed to specify sort fields and 'null' means all fields are allowed. |
||
77 | * |
||
78 | * @var string[]|null |
||
79 | */ |
||
80 | protected $allowedSortFields = []; |
||
81 | |||
82 | /** |
||
83 | * A list of allowed pagination input parameters (e.g 'number', 'size', 'offset' and etc). |
||
84 | * |
||
85 | * Empty array [] means clients are not allowed to specify paging and 'null' means all parameters are allowed. |
||
86 | * |
||
87 | * @var string[]|null |
||
88 | */ |
||
89 | protected $allowedPagingParameters = []; |
||
90 | |||
91 | /** |
||
92 | * A list of allowed filtering input parameters. |
||
93 | * |
||
94 | * Empty array [] means clients are not allowed to specify filtering and 'null' means all parameters are allowed. |
||
95 | * |
||
96 | * @var string[]|null |
||
97 | */ |
||
98 | protected $allowedFilteringParameters = []; |
||
99 | |||
100 | /** |
||
101 | * JSON API extensions supported by this controller (comma separated). |
||
102 | * |
||
103 | * @var string |
||
104 | */ |
||
105 | protected $extensions = MediaTypeInterface::NO_EXT; |
||
106 | |||
107 | /** |
||
108 | * If JSON API extension should be allowed. |
||
109 | * |
||
110 | * @var bool |
||
111 | */ |
||
112 | protected $allowExtensionsSupport = false; |
||
113 | |||
114 | /** |
||
115 | * @var IntegrationInterface |
||
116 | */ |
||
117 | private $integration; |
||
118 | |||
119 | /** |
||
120 | * @var CodecMatcherInterface |
||
121 | */ |
||
122 | private $codecMatcher; |
||
123 | |||
124 | /** |
||
125 | * @var ParametersParserInterface |
||
126 | */ |
||
127 | private $parametersParser; |
||
128 | |||
129 | /** |
||
130 | * @var ParametersCheckerInterface |
||
131 | */ |
||
132 | private $parametersChecker; |
||
133 | |||
134 | /** |
||
135 | * @var ExceptionThrowerInterface |
||
136 | */ |
||
137 | private $exceptionThrower; |
||
138 | |||
139 | /** |
||
140 | * @var ParametersInterface |
||
141 | */ |
||
142 | private $parameters = null; |
||
143 | |||
144 | /** |
||
145 | * @var bool |
||
146 | */ |
||
147 | private $parametersChecked = false; |
||
148 | |||
149 | /** |
||
150 | * @var SupportedExtensionsInterface |
||
151 | */ |
||
152 | private $supportedExtensions; |
||
153 | |||
154 | /** |
||
155 | * Init integrations with JSON API implementation. |
||
156 | * |
||
157 | * @param IntegrationInterface $integration |
||
158 | * |
||
159 | * @return void |
||
160 | */ |
||
161 | 7 | private function initJsonApiSupport(IntegrationInterface $integration) |
|
187 | |||
188 | /** |
||
189 | * @return mixed |
||
190 | */ |
||
191 | 1 | protected function getDocument() |
|
200 | |||
201 | /** |
||
202 | * @return ParametersInterface |
||
203 | */ |
||
204 | 6 | protected function getUncheckedParameters() |
|
212 | |||
213 | /** |
||
214 | * @return void |
||
215 | */ |
||
216 | 6 | protected function checkParameters() |
|
221 | |||
222 | /** |
||
223 | * @return void |
||
224 | */ |
||
225 | 1 | protected function checkParametersEmpty() |
|
229 | |||
230 | /** |
||
231 | * @return ParametersInterface |
||
232 | */ |
||
233 | 4 | protected function getParameters() |
|
241 | |||
242 | /** |
||
243 | * Get response with HTTP code only. |
||
244 | * |
||
245 | * @param $statusCode |
||
246 | * |
||
247 | * @return Response |
||
248 | */ |
||
249 | 1 | protected function getCodeResponse($statusCode) |
|
259 | |||
260 | /** |
||
261 | * Get response with meta information only. |
||
262 | * |
||
263 | * @param array|object $meta Meta information. |
||
264 | * @param int $statusCode |
||
265 | * |
||
266 | * @return Response |
||
267 | */ |
||
268 | 1 | protected function getMetaResponse($meta, $statusCode = Response::HTTP_OK) |
|
280 | |||
281 | /** |
||
282 | * @return SupportedExtensionsInterface |
||
283 | */ |
||
284 | 1 | protected function getSupportedExtensions() |
|
288 | |||
289 | /** |
||
290 | * Get response with regular JSON API Document in body. |
||
291 | * |
||
292 | * @param object|array $data |
||
293 | * @param int $statusCode |
||
294 | * @param array<string,\Neomerx\JsonApi\Contracts\Schema\LinkInterface>|null $links |
||
295 | * @param mixed $meta |
||
296 | * |
||
297 | * @return Response |
||
298 | */ |
||
299 | 1 | protected function getContentResponse( |
|
318 | |||
319 | /** |
||
320 | * @param object $resource |
||
321 | * @param array<string,\Neomerx\JsonApi\Contracts\Schema\LinkInterface>|null $links |
||
322 | * @param mixed $meta |
||
323 | * |
||
324 | * @return Response |
||
325 | */ |
||
326 | 1 | protected function getCreatedResponse( |
|
352 | |||
353 | /** |
||
354 | * @return IntegrationInterface |
||
355 | */ |
||
356 | 7 | private function getIntegration() |
|
361 | } |
||
362 |