@@ -66,12 +66,12 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
6666 continue ;
6767 }
6868
69- if (!$ type = $ argument ->getType ()) {
69+ if (!$ argument ->getType ()) {
7070 throw new \LogicException (sprintf ('Could not resolve the "$%s" controller argument: argument should be typed. ' , $ argument ->getName ()));
7171 }
7272
7373 try {
74- $ payload = $ this ->$ payloadMapper ($ request , $ type , $ attributes [0 ], $ argument );
74+ $ payload = $ this ->$ payloadMapper ($ request , $ argument , $ attributes [0 ]);
7575 } catch (PartialDenormalizationException $ e ) {
7676 throw new HttpException ($ validationFailedCode , implode ("\n" , array_map (static fn (NotNormalizableValueException $ e ) => $ e ->getMessage (), $ e ->getErrors ())), $ e );
7777 }
@@ -89,19 +89,19 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
8989 return [];
9090 }
9191
92- private function mapQueryString (Request $ request , string $ type , MapQueryString $ attribute ): ?object
92+ private function mapQueryString (Request $ request , ArgumentMetadata $ argument , MapQueryString $ attribute ): ?object
9393 {
9494 if (!$ data = $ request ->query ->all ()) {
9595 return null ;
9696 }
9797
98- return $ this ->serializer ->denormalize ($ data , $ type , self ::DEFAULT_FORMAT , self ::CONTEXT_DENORMALIZE + $ attribute ->context );
98+ return $ this ->serializer ->denormalize ($ data , $ argument -> getType () , self ::DEFAULT_FORMAT , self ::CONTEXT_DENORMALIZE + $ attribute ->context );
9999 }
100100
101- private function mapRequestPayload (Request $ request , string $ type , MapRequestPayload $ attribute ): ?object
101+ private function mapRequestPayload (Request $ request , ArgumentMetadata $ argument , MapRequestPayload $ attribute ): ?object
102102 {
103103 if ($ data = $ request ->request ->all ()) {
104- return $ this ->serializer ->denormalize ($ data , $ type , self ::DEFAULT_FORMAT , self ::CONTEXT_DENORMALIZE + $ attribute ->context );
104+ return $ this ->serializer ->denormalize ($ data , $ argument -> getType () , self ::DEFAULT_FORMAT , self ::CONTEXT_DENORMALIZE + $ attribute ->context );
105105 }
106106
107107 if ('' === $ data = $ request ->getContent ()) {
@@ -111,24 +111,21 @@ private function mapRequestPayload(Request $request, string $type, MapRequestPay
111111 $ format = $ request ->getRequestFormat (self ::DEFAULT_FORMAT );
112112
113113 try {
114- return $ this ->serializer ->deserialize ($ data , $ type , $ format , self ::CONTEXT_DESERIALIZE + $ attribute ->context );
114+ return $ this ->serializer ->deserialize ($ data , $ argument -> getType () , $ format , self ::CONTEXT_DESERIALIZE + $ attribute ->context );
115115 } catch (UnsupportedFormatException $ e ) {
116116 throw new HttpException (Response::HTTP_UNSUPPORTED_MEDIA_TYPE , sprintf ('Unsupported format: "%s". ' , $ format ), $ e );
117117 } catch (NotEncodableValueException $ e ) {
118118 throw new HttpException (Response::HTTP_BAD_REQUEST , sprintf ('Request payload contains not valid "%s". ' , $ format ), $ e );
119119 }
120120 }
121121
122- private function mapUploadedFile (Request $ request , string $ type , MapUploadedFile $ attribute, ArgumentMetadata $ argument ): ? UploadedFile
122+ private function mapUploadedFile (Request $ request , ArgumentMetadata $ argument , MapUploadedFile $ attribute ): UploadedFile | array | null
123123 {
124- if (UploadedFile::class !== $ type ) {
125- throw new \InvalidArgumentException (sprintf ('Unexpected type "%s". Expected "%s". ' , $ type , UploadedFile::class));
126- }
127-
128124 $ name = $ attribute ->name ?? $ argument ->getName ();
129125 $ file = $ request ->files ->get ($ name );
130- if (!$ file instanceof UploadedFile) {
131- return null ;
126+ $ type = get_debug_type ($ file );
127+ if ($ type !== $ argument ->getType () && !('null ' === $ type && $ argument ->isNullable ())) {
128+ throw new \InvalidArgumentException (sprintf ('Unexpected type "%s". Expected "%s". ' , $ type , $ argument ->getType ()));
132129 }
133130
134131 return $ file ;
0 commit comments