1 | <?php |
||
37 | class JsonApiService implements JsonApiServiceInterface |
||
38 | { |
||
39 | /** |
||
40 | * @var FactoryInterface |
||
41 | */ |
||
42 | protected $factory; |
||
43 | |||
44 | /** |
||
45 | * @var JsonApiRegistryInterface |
||
46 | */ |
||
47 | protected $registry; |
||
48 | |||
49 | /** |
||
50 | * @var ContainerInterface |
||
51 | */ |
||
52 | protected $schemas; |
||
53 | |||
54 | /** |
||
55 | * @var ValidationServiceInterface |
||
56 | */ |
||
57 | protected $validator; |
||
58 | |||
59 | /** |
||
60 | * @var DataParserInterface |
||
61 | */ |
||
62 | protected $parser; |
||
63 | |||
64 | /** |
||
65 | * Constructor |
||
66 | * |
||
67 | * @param FactoryInterface $factory |
||
68 | * @param JsonApiRegistryInterface $registry |
||
69 | * @param ContainerInterface $schemas |
||
70 | * @param DataParserInterface $parser |
||
71 | * @param ValidationServiceInterface $validator |
||
72 | */ |
||
73 | public function __construct( |
||
86 | |||
87 | /** |
||
88 | * @inheritdoc |
||
89 | */ |
||
90 | public function getFactory() |
||
94 | |||
95 | /** |
||
96 | * @inheritdoc |
||
97 | */ |
||
98 | public function parseRequest(Request $request, EnvironmentInterface $environment = null) |
||
117 | |||
118 | /** |
||
119 | * @inheritdoc |
||
120 | */ |
||
121 | public function validateRequest(RequestInterface $request) |
||
152 | |||
153 | /** |
||
154 | * @inheritdoc |
||
155 | */ |
||
156 | public function getResponseFactory(RequestInterface $request) |
||
160 | |||
161 | /** |
||
162 | * Returns JSON API environment configured in request |
||
163 | * |
||
164 | * @param Request $request |
||
165 | * @return EnvironmentInterface |
||
166 | */ |
||
167 | protected function getRequestEnvironment(Request $request) |
||
183 | |||
184 | /** |
||
185 | * Initialize JSON API environment for specified request |
||
186 | * |
||
187 | * @param EnvironmentInterface $environment |
||
188 | * @param Request $request |
||
189 | */ |
||
190 | private function initializeEnvironment(EnvironmentInterface $environment, Request $request) |
||
201 | |||
202 | /** |
||
203 | * Create codec matcher for specified environment |
||
204 | * |
||
205 | * @param EnvironmentInterface $environment |
||
206 | * @return \Neomerx\JsonApi\Contracts\Codec\CodecMatcherInterface |
||
207 | */ |
||
208 | private function createMatcher(EnvironmentInterface $environment) |
||
223 | |||
224 | /** |
||
225 | * Convert media type string to media type object |
||
226 | * |
||
227 | * @param string $type |
||
228 | * @return \Neomerx\JsonApi\Contracts\Http\Headers\MediaTypeInterface |
||
229 | */ |
||
230 | private function parseMediaTypeString($type) |
||
239 | |||
240 | /** |
||
241 | * Parse request headers and detect appropriate decoder and encoder |
||
242 | * |
||
243 | * @param Request $request |
||
244 | * @param CodecMatcherInterface $matcher |
||
245 | */ |
||
246 | private function parseRequestHeaders(Request $request, CodecMatcherInterface $matcher) |
||
254 | |||
255 | /** |
||
256 | * Create PSR7 request from symfony http foundation request |
||
257 | * |
||
258 | * @param Request $request |
||
259 | * @return Psr7Request |
||
260 | */ |
||
261 | private function createPsr7Request(Request $request) |
||
275 | |||
276 | /** |
||
277 | * Parse request query parameters |
||
278 | * |
||
279 | * @param Request $request |
||
280 | * @param EnvironmentInterface $environment |
||
281 | * @return \Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface|null |
||
282 | */ |
||
283 | private function parseQuery(Request $request, EnvironmentInterface $environment) |
||
298 | |||
299 | /** |
||
300 | * Parse request body |
||
301 | * |
||
302 | * @param Request $request |
||
303 | * @param EnvironmentInterface $environment |
||
304 | * @return mixed|null |
||
305 | */ |
||
306 | private function parseBody(Request $request, EnvironmentInterface $environment) |
||
319 | |||
320 | /** |
||
321 | * Validate specified data |
||
322 | * |
||
323 | * @param mixed $data |
||
324 | * @param array $validationGroups |
||
325 | * @return Error[] |
||
326 | */ |
||
327 | private function validateData($data = null, array $validationGroups = []) |
||
331 | |||
332 | /** |
||
333 | * Register specified decoders |
||
334 | * |
||
335 | * @param array $decoders |
||
336 | * @param CodecMatcherInterface $matcher |
||
337 | */ |
||
338 | private function registerDecoders(array $decoders, CodecMatcherInterface $matcher) |
||
347 | |||
348 | /** |
||
349 | * Register specified encoders |
||
350 | * |
||
351 | * @param array $encoders |
||
352 | * @param CodecMatcherInterface $matcher |
||
353 | */ |
||
354 | private function registerEncoders(array $encoders, CodecMatcherInterface $matcher) |
||
363 | } |
||
364 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.