1 | <?php |
||
36 | class JsonApiService implements JsonApiServiceInterface |
||
37 | { |
||
38 | /** |
||
39 | * @var FactoryInterface |
||
40 | */ |
||
41 | protected $factory; |
||
42 | |||
43 | /** |
||
44 | * @var JsonApiRegistryInterface |
||
45 | */ |
||
46 | protected $registry; |
||
47 | |||
48 | /** |
||
49 | * @var ContainerInterface |
||
50 | */ |
||
51 | protected $schemas; |
||
52 | |||
53 | /** |
||
54 | * @var ValidationServiceInterface |
||
55 | */ |
||
56 | protected $validator; |
||
57 | |||
58 | /** |
||
59 | * @var DataParserInterface |
||
60 | */ |
||
61 | protected $parser; |
||
62 | |||
63 | /** |
||
64 | * Constructor |
||
65 | * |
||
66 | * @param FactoryInterface $factory |
||
67 | * @param JsonApiRegistryInterface $registry |
||
68 | * @param ContainerInterface $schemas |
||
69 | * @param DataParserInterface $parser |
||
70 | * @param ValidationServiceInterface $validator |
||
71 | */ |
||
72 | 6 | public function __construct( |
|
85 | |||
86 | /** |
||
87 | * @inheritdoc |
||
88 | */ |
||
89 | public function getFactory() |
||
93 | |||
94 | /** |
||
95 | * @inheritdoc |
||
96 | */ |
||
97 | 6 | public function parseRequest(Request $request, EnvironmentInterface $environment = null) |
|
122 | |||
123 | /** |
||
124 | * @inheritdoc |
||
125 | */ |
||
126 | 2 | public function validateRequest(RequestInterface $request) |
|
157 | |||
158 | /** |
||
159 | * @inheritdoc |
||
160 | */ |
||
161 | 1 | public function getResponseFactory(RequestInterface $request) |
|
165 | |||
166 | /** |
||
167 | * Returns JSON API environment configured in request |
||
168 | * |
||
169 | * @param Request $request |
||
170 | * @return EnvironmentInterface |
||
171 | */ |
||
172 | 6 | public function getRequestEnvironment(Request $request) |
|
188 | |||
189 | /** |
||
190 | * Initialize JSON API environment for specified request |
||
191 | * |
||
192 | * @param EnvironmentInterface $environment |
||
193 | * @param Request $request |
||
194 | */ |
||
195 | 4 | private function initializeEnvironment(EnvironmentInterface $environment, Request $request) |
|
206 | |||
207 | /** |
||
208 | * Create codec matcher for specified environment |
||
209 | * |
||
210 | * @param EnvironmentInterface $environment |
||
211 | * @return \Neomerx\JsonApi\Contracts\Codec\CodecMatcherInterface |
||
212 | */ |
||
213 | 4 | private function createMatcher(EnvironmentInterface $environment) |
|
228 | |||
229 | /** |
||
230 | * Convert media type string to media type object |
||
231 | * |
||
232 | * @param string $type |
||
233 | * @return \Neomerx\JsonApi\Contracts\Http\Headers\MediaTypeInterface |
||
234 | */ |
||
235 | 4 | private function parseMediaTypeString($type) |
|
244 | |||
245 | /** |
||
246 | * Parse request headers and detect appropriate decoder and encoder |
||
247 | * |
||
248 | * @param Request $request |
||
249 | * @param CodecMatcherInterface $matcher |
||
250 | */ |
||
251 | 3 | private function parseRequestHeaders(Request $request, CodecMatcherInterface $matcher) |
|
259 | |||
260 | /** |
||
261 | * Create PSR7 request from symfony http foundation request |
||
262 | * |
||
263 | * @param Request $request |
||
264 | * @return Psr7Request |
||
265 | */ |
||
266 | 3 | private function createPsr7Request(Request $request) |
|
285 | |||
286 | /** |
||
287 | * Parse request query parameters |
||
288 | * |
||
289 | * @param Request $request |
||
290 | * @param EnvironmentInterface $environment |
||
291 | * @return \Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface|null |
||
292 | */ |
||
293 | 3 | private function parseQuery(Request $request, EnvironmentInterface $environment) |
|
308 | |||
309 | /** |
||
310 | * Parse request body |
||
311 | * |
||
312 | * @param Request $request |
||
313 | * @param EnvironmentInterface $environment |
||
314 | * @return mixed|null |
||
315 | */ |
||
316 | 3 | private function parseBody(Request $request, EnvironmentInterface $environment) |
|
329 | |||
330 | /** |
||
331 | * Validate specified data |
||
332 | * |
||
333 | * @param mixed $data |
||
334 | * @param array|null $validationGroups |
||
335 | * @return Error[] |
||
336 | */ |
||
337 | 2 | private function validateData($data = null, array $validationGroups = null) |
|
341 | |||
342 | /** |
||
343 | * Register specified decoders |
||
344 | * |
||
345 | * @param array $decoders |
||
346 | * @param CodecMatcherInterface $matcher |
||
347 | */ |
||
348 | 4 | private function registerDecoders(array $decoders, CodecMatcherInterface $matcher) |
|
357 | |||
358 | /** |
||
359 | * Register specified encoders |
||
360 | * |
||
361 | * @param array $encoders |
||
362 | * @param CodecMatcherInterface $matcher |
||
363 | */ |
||
364 | 3 | private function registerEncoders(array $encoders, CodecMatcherInterface $matcher) |
|
373 | } |
||
374 |