1 | <?php |
||
30 | class RequestBodyParamConverter implements ParamConverterInterface |
||
31 | { |
||
32 | private $serializer; |
||
33 | private $context = []; |
||
34 | private $validator; |
||
35 | |||
36 | /** |
||
37 | * The name of the argument on which the ConstraintViolationList will be set. |
||
38 | * |
||
39 | * @var null|string |
||
40 | */ |
||
41 | private $validationErrorsArgument; |
||
42 | |||
43 | /** |
||
44 | * @param Serializer $serializer |
||
45 | * @param array|null $groups An array of groups to be used in the serialization context |
||
46 | * @param string|null $version A version string to be used in the serialization context |
||
47 | * @param ValidatorInterface $validator |
||
48 | * @param string|null $validationErrorsArgument |
||
49 | * |
||
50 | * @throws \InvalidArgumentException |
||
51 | */ |
||
52 | 16 | public function __construct( |
|
53 | Serializer $serializer, |
||
54 | $groups = null, |
||
55 | $version = null, |
||
56 | ValidatorInterface $validator = null, |
||
57 | $validationErrorsArgument = null |
||
58 | ) { |
||
59 | 16 | $this->serializer = $serializer; |
|
60 | |||
61 | 16 | if (!empty($groups)) { |
|
62 | 1 | $this->context['groups'] = (array) $groups; |
|
63 | 1 | } |
|
64 | |||
65 | 16 | if (!empty($version)) { |
|
66 | 1 | $this->context['version'] = $version; |
|
67 | 1 | } |
|
68 | |||
69 | 16 | if (null !== $validator && null === $validationErrorsArgument) { |
|
70 | throw new \InvalidArgumentException('"$validationErrorsArgument" cannot be null when using the validator'); |
||
71 | } |
||
72 | |||
73 | 16 | $this->validator = $validator; |
|
74 | 16 | $this->validationErrorsArgument = $validationErrorsArgument; |
|
75 | 16 | } |
|
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | 9 | public function apply(Request $request, ParamConverter $configuration) |
|
121 | |||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | 4 | public function supports(ParamConverter $configuration) |
|
129 | |||
130 | /** |
||
131 | * @param Context $context |
||
132 | * @param array $options |
||
133 | */ |
||
134 | 10 | protected function configureContext(Context $context, array $options) |
|
153 | |||
154 | /** |
||
155 | * Throws an exception or return false if a ParamConverter is optional. |
||
156 | */ |
||
157 | 3 | private function throwException(\Exception $exception, ParamConverter $configuration) |
|
165 | |||
166 | /** |
||
167 | * @param array $options |
||
168 | * |
||
169 | * @return array |
||
170 | */ |
||
171 | 2 | private function getValidatorOptions(array $options) |
|
182 | } |
||
183 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.