@@ -66,12 +66,12 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
66
66
continue ;
67
67
}
68
68
69
- if (!$ type = $ argument ->getType ()) {
69
+ if (!$ argument ->getType ()) {
70
70
throw new \LogicException (sprintf ('Could not resolve the "$%s" controller argument: argument should be typed. ' , $ argument ->getName ()));
71
71
}
72
72
73
73
try {
74
- $ payload = $ this ->$ payloadMapper ($ request , $ type , $ attributes [0 ], $ argument );
74
+ $ payload = $ this ->$ payloadMapper ($ request , $ argument , $ attributes [0 ]);
75
75
} catch (PartialDenormalizationException $ e ) {
76
76
throw new HttpException ($ validationFailedCode , implode ("\n" , array_map (static fn (NotNormalizableValueException $ e ) => $ e ->getMessage (), $ e ->getErrors ())), $ e );
77
77
}
@@ -89,19 +89,19 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
89
89
return [];
90
90
}
91
91
92
- private function mapQueryString (Request $ request , string $ type , MapQueryString $ attribute ): ?object
92
+ private function mapQueryString (Request $ request , ArgumentMetadata $ argument , MapQueryString $ attribute ): ?object
93
93
{
94
94
if (!$ data = $ request ->query ->all ()) {
95
95
return null ;
96
96
}
97
97
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 );
99
99
}
100
100
101
- private function mapRequestPayload (Request $ request , string $ type , MapRequestPayload $ attribute ): ?object
101
+ private function mapRequestPayload (Request $ request , ArgumentMetadata $ argument , MapRequestPayload $ attribute ): ?object
102
102
{
103
103
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 );
105
105
}
106
106
107
107
if ('' === $ data = $ request ->getContent ()) {
@@ -111,24 +111,21 @@ private function mapRequestPayload(Request $request, string $type, MapRequestPay
111
111
$ format = $ request ->getRequestFormat (self ::DEFAULT_FORMAT );
112
112
113
113
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 );
115
115
} catch (UnsupportedFormatException $ e ) {
116
116
throw new HttpException (Response::HTTP_UNSUPPORTED_MEDIA_TYPE , sprintf ('Unsupported format: "%s". ' , $ format ), $ e );
117
117
} catch (NotEncodableValueException $ e ) {
118
118
throw new HttpException (Response::HTTP_BAD_REQUEST , sprintf ('Request payload contains not valid "%s". ' , $ format ), $ e );
119
119
}
120
120
}
121
121
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
123
123
{
124
- if (UploadedFile::class !== $ type ) {
125
- throw new \InvalidArgumentException (sprintf ('Unexpected type "%s". Expected "%s". ' , $ type , UploadedFile::class));
126
- }
127
-
128
124
$ name = $ attribute ->name ?? $ argument ->getName ();
129
125
$ 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 ()));
132
129
}
133
130
134
131
return $ file ;
0 commit comments