@@ -21,9 +21,8 @@ public static function generateRequest(
2121 }
2222
2323 $ propertyTypes = self ::getParamTypes ($ requestClass , $ method );
24- $ cacheJsonContent = null ;
2524 $ constructorArgs = array_map (
26- fn (RequestProperty $ propertyType ) => self ::getConstructorArgument ($ request , $ propertyType, $ cacheJsonContent ),
25+ fn (RequestProperty $ propertyType ) => self ::getConstructorArgument ($ request , $ propertyType ),
2726 $ propertyTypes ,
2827 );
2928
@@ -37,16 +36,10 @@ public static function generateRequest(
3736 private static function getConstructorArgument (
3837 Request $ request ,
3938 RequestProperty $ propertyType ,
40- ?array &$ cacheJsonContent ,
4139 ): mixed {
42- if ($ propertyType ->type === InputParamType::Json && !isset ($ cacheJsonContent )) {
43- $ cacheJsonContent = $ request ->content ->getParsedBody () ?? [];
44- }
45-
4640 $ content = (match ($ propertyType ->type ) {
4741 InputParamType::Query => $ request ->query [$ propertyType ->name ] ?? null ,
48- InputParamType::Json => $ cacheJsonContent [$ propertyType ->name ] ?? null ,
49- InputParamType::Input => $ request ->input [$ propertyType ->name ] ?? null ,
42+ InputParamType::Input, InputParamType::Json => $ request ->input [$ propertyType ->name ] ?? null ,
5043 InputParamType::Header => $ request ->headers [strtolower ($ propertyType ->name )] ?? null ,
5144 InputParamType::Cookie => $ request ->cookies [$ propertyType ->name ] ?? null ,
5245 default => null ,
@@ -111,6 +104,7 @@ public static function getParamTypes(string $requestClass, ?string $httpMethod,
111104
112105 $ constructorParams = $ constructor ->getParameters ();
113106 $ result = [];
107+ $ contentType = null ;
114108
115109 foreach ($ constructorParams as $ param ) {
116110 $ property = $ reflectionClass ->getProperty ($ param ->getName ());
@@ -150,6 +144,17 @@ public static function getParamTypes(string $requestClass, ?string $httpMethod,
150144 $ subProperties = RequestParser::getParamTypes ($ propertyType ->getName (), $ httpMethod , false );
151145 }
152146
147+ if (!isset ($ contentType ) && in_array ($ inputParamType , [InputParamType::Input, InputParamType::Json], true )) {
148+ $ contentType = $ inputParamType ;
149+ } elseif (in_array ($ inputParamType , [InputParamType::Input, InputParamType::Json], true )
150+ && $ inputParamType != $ contentType
151+ ) {
152+ throw new InvalidArgumentException (
153+ "Request class $ requestClass has conflicting input types for property $ name. "
154+ . "Cannot be both $ inputParamType and $ contentType " ,
155+ );
156+ }
157+
153158 $ result [] = new RequestProperty (
154159 name: $ name ,
155160 propertyName: $ property ->getName (),
0 commit comments