Total Complexity | 7 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | class PayloadParamConverter implements ParamConverterInterface |
||
13 | { |
||
14 | use ToggleableDeserializationTrait; |
||
15 | |||
16 | public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFactory) |
||
17 | { |
||
18 | $this->resourceMetadataFactory = $resourceMetadataFactory; |
||
19 | } |
||
20 | |||
21 | public function apply(Request $request, ParamConverter $configuration) |
||
22 | { |
||
23 | $class = $configuration->getClass(); |
||
24 | |||
25 | if (null === $class) { |
||
|
|||
26 | throw new \InvalidArgumentException(sprintf( |
||
27 | '%s only supports parameters with class type declaration.', |
||
28 | self::class |
||
29 | )); |
||
30 | } |
||
31 | |||
32 | $attributes = RequestAttributesExtractor::extractAttributes($request); |
||
33 | |||
34 | if (!$this->isRequestToDeserialize($request, $attributes)) { |
||
35 | return false; |
||
36 | } |
||
37 | |||
38 | $data = $request->attributes->get('data'); |
||
39 | |||
40 | if (!$data instanceof $class || get_class($data) !== $attributes['resource_class']) { |
||
41 | return false; |
||
42 | } |
||
43 | |||
44 | $request->attributes->set($configuration->getName(), $data); |
||
45 | |||
46 | return true; |
||
47 | } |
||
48 | |||
49 | public function supports(ParamConverter $configuration) |
||
52 | } |
||
53 | } |
||
54 |