@@ -69,14 +69,14 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
6969 continue ;
7070 }
7171
72- if (!$ type = $ argument ->getType ()) {
72+ if (!$ argument ->getType ()) {
7373 throw new \LogicException (sprintf ('Could not resolve the "$%s" controller argument: argument should be typed. ' , $ argument ->getName ()));
7474 }
7575
7676 if ($ this ->validator ) {
7777 $ violations = new ConstraintViolationList ();
7878 try {
79- $ payload = $ this ->$ payloadMapper ($ request , $ type , $ attributes [0 ]);
79+ $ payload = $ this ->$ payloadMapper ($ request , $ argument , $ attributes [0 ]);
8080 } catch (PartialDenormalizationException $ e ) {
8181 $ trans = $ this ->translator ? $ this ->translator ->trans (...) : fn ($ m , $ p ) => strtr ($ m , $ p );
8282 foreach ($ e ->getErrors () as $ error ) {
@@ -92,15 +92,15 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
9292 }
9393
9494 if (null !== $ payload ) {
95- $ violations ->addAll ($ this ->validator ->validate ($ payload ));
95+ $ violations ->addAll ($ this ->validator ->validate ($ payload, null , $ attributes [ 0 ]-> groups ?? null ));
9696 }
9797
9898 if (\count ($ violations )) {
9999 throw new HttpException ($ validationFailedCode , implode ("\n" , array_map (static fn ($ e ) => $ e ->getMessage (), iterator_to_array ($ violations ))), new ValidationFailedException ($ payload , $ violations ));
100100 }
101101 } else {
102102 try {
103- $ payload = $ this ->$ payloadMapper ($ request , $ type , $ attributes [0 ]);
103+ $ payload = $ this ->$ payloadMapper ($ request , $ argument , $ attributes [0 ]);
104104 } catch (PartialDenormalizationException $ e ) {
105105 throw new HttpException ($ validationFailedCode , implode ("\n" , array_map (static fn ($ e ) => $ e ->getMessage (), $ e ->getErrors ())), $ e );
106106 }
@@ -114,19 +114,19 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
114114 return [];
115115 }
116116
117- private function mapQueryString (Request $ request , string $ type , MapQueryString $ attribute ): ?object
117+ private function mapQueryString (Request $ request , ArgumentMetadata $ argument , MapQueryString $ attribute ): ?object
118118 {
119119 if (!$ data = $ request ->query ->all ()) {
120120 return null ;
121121 }
122122
123- return $ this ->serializer ->denormalize ($ data , $ type , null , self ::CONTEXT_DENORMALIZE + $ attribute ->context );
123+ return $ this ->serializer ->denormalize ($ data , $ argument -> getType () , null , self ::CONTEXT_DENORMALIZE + $ attribute ->context );
124124 }
125125
126- private function mapRequestPayload (Request $ request , string $ type , MapRequestPayload $ attribute ): ?object
126+ private function mapRequestPayload (Request $ request , ArgumentMetadata $ argument , MapRequestPayload $ attribute ): ?object
127127 {
128128 if ($ data = $ request ->request ->all ()) {
129- return $ this ->serializer ->denormalize ($ data , $ type , null , self ::CONTEXT_DENORMALIZE + $ attribute ->context );
129+ return $ this ->serializer ->denormalize ($ data , $ argument -> getType () , null , self ::CONTEXT_DENORMALIZE + $ attribute ->context );
130130 }
131131
132132 if ('' === $ data = $ request ->getContent ()) {
@@ -137,12 +137,17 @@ private function mapRequestPayload(Request $request, string $type, MapRequestPay
137137 throw new HttpException (Response::HTTP_UNSUPPORTED_MEDIA_TYPE , 'Unsupported format. ' );
138138 }
139139
140+ $ acceptedFormats = \is_string ($ attribute ->format ) ? [$ attribute ->format ] : $ attribute ->format ;
141+ if (\is_array ($ attribute ->format ) && !\in_array ($ format , $ acceptedFormats , true )) {
142+ throw new HttpException (Response::HTTP_UNSUPPORTED_MEDIA_TYPE , sprintf ('Unsupported format, expects "%s", but "%s" given. ' , implode ('", " ' , $ acceptedFormats ), $ format ));
143+ }
144+
140145 if ('form ' === $ format ) {
141146 throw new HttpException (Response::HTTP_BAD_REQUEST , 'Request payload contains invalid "form" data. ' );
142147 }
143148
144149 try {
145- return $ this ->serializer ->deserialize ($ data , $ type , $ format , self ::CONTEXT_DESERIALIZE + $ attribute ->context );
150+ return $ this ->serializer ->deserialize ($ data , $ argument -> getType () , $ format , self ::CONTEXT_DESERIALIZE + $ attribute ->context );
146151 } catch (UnsupportedFormatException $ e ) {
147152 throw new HttpException (Response::HTTP_UNSUPPORTED_MEDIA_TYPE , sprintf ('Unsupported format: "%s". ' , $ format ), $ e );
148153 } catch (NotEncodableValueException $ e ) {
0 commit comments