1212use App \Exceptions \WrongHttpMethodException ;
1313use App \Exceptions \NotImplementedException ;
1414use App \Exceptions \InternalServerException ;
15- use App \Exceptions \InvalidApiArgumentException ;
1615use App \Exceptions \FrontendErrorMappings ;
1716use App \Security \AccessManager ;
1817use App \Security \Authorizator ;
2726use App \Responses \StorageFileResponse ;
2827use App \Responses \ZipFilesResponse ;
2928use Nette \Application \Application ;
30- use Nette \Application \Request ;
3129use Nette \Http \IResponse ;
3230use Tracy \ILogger ;
3331use ReflectionClass ;
@@ -130,7 +128,7 @@ public function startup()
130128 $ this ->tryCall ($ this ->formatPermissionCheckMethod ($ this ->getAction ()), $ this ->params );
131129
132130 Validators::init ();
133- $ this ->processParams ($ this -> getRequest (), $ actionReflection );
131+ $ this ->processParams ($ actionReflection );
134132 }
135133
136134 protected function isRequestJson (): bool
@@ -206,30 +204,28 @@ public function getFormatInstance(): MetaFormat
206204 return $ this ->requestFormatInstance ;
207205 }
208206
209- private function processParams (Request $ request , ReflectionMethod $ reflection )
207+ private function processParams (ReflectionMethod $ reflection )
210208 {
211209 // use a method specialized for formats if there is a format available
212210 $ format = MetaFormatHelper::extractFormatFromAttribute ($ reflection );
213211 if ($ format !== null ) {
214- $ this ->requestFormatInstance = $ this ->processParamsFormat ($ request , $ format , null );
212+ $ this ->requestFormatInstance = $ this ->processParamsFormat ($ format , null );
215213 }
216214
217215 // handle loose parameters
218216 $ paramData = MetaFormatHelper::extractRequestParamData ($ reflection );
219- $ this ->processParamsLoose ($ request , $ paramData );
217+ $ this ->processParamsLoose ($ paramData );
220218 }
221219
222220 /**
223221 * Processes loose parameters. Request parameters are validated, no new data is created.
224- * @throws InvalidApiArgumentException Thrown when the request parameter values do not conform to the definition.
225- * @param Request $request Request object holding the request data.
226222 * @param array $paramData Parameter data to be validated.
227223 */
228- private function processParamsLoose (Request $ request , array $ paramData )
224+ private function processParamsLoose (array $ paramData )
229225 {
230226 // validate each param
231227 foreach ($ paramData as $ param ) {
232- $ paramValue = $ this ->getValueFromParamData ($ request , $ param );
228+ $ paramValue = $ this ->getValueFromParamData ($ param );
233229
234230 // this throws when it does not conform
235231 $ param ->conformsToDefinition ($ paramValue );
@@ -239,17 +235,15 @@ private function processParamsLoose(Request $request, array $paramData)
239235 /**
240236 * Processes parameters defined by a format. Request parameters are validated and a format instance with
241237 * parameter values created.
242- * @param Request $request Request object holding the request data.
243238 * @param string $format The format defining the parameters.
244239 * @param ?array $valueDictionary If not null, a nested format instance will be created. The values will be taken
245240 * from here instead of the request object. Format validation ignores parameter type (path, query or post).
246241 * A top-level format will be created if null.
247242 * @throws InternalServerException Thrown when the format definition is corrupted/absent.
248- * @throws BadRequestException Thrown when the request parameter values do not meet the structural constraints.
249- * @throws InvalidApiArgumentException Thrown when the request parameter values do not conform to the definition.
243+ * @throws BadRequestException Thrown when the request parameter values do not conform to the definition.
250244 * @return MetaFormat Returns a format instance with values filled from the request object.
251245 */
252- private function processParamsFormat (Request $ request , string $ format , ?array $ valueDictionary ): MetaFormat
246+ private function processParamsFormat (string $ format , ?array $ valueDictionary ): MetaFormat
253247 {
254248 // get the parsed attribute data from the format fields
255249 $ formatToFieldDefinitionsMap = FormatCache::getFormatToFieldDefinitionsMap ();
@@ -265,7 +259,7 @@ private function processParamsFormat(Request $request, string $format, ?array $v
265259 $ value = null ;
266260 // top-level format
267261 if ($ valueDictionary === null ) {
268- $ value = $ this ->getValueFromParamData ($ request , $ requestParamData );
262+ $ value = $ this ->getValueFromParamData ($ requestParamData );
269263 // nested format
270264 } else {
271265 // Instead of retrieving the values with the getRequest call, use the provided $valueDictionary.
@@ -281,7 +275,7 @@ private function processParamsFormat(Request $request, string $format, ?array $v
281275 // replace the value dictionary stored in $value with a format instance
282276 $ nestedFormatName = $ requestParamData ->getFormatName ();
283277 if ($ nestedFormatName !== null ) {
284- $ value = $ this ->processParamsFormat ($ request , $ nestedFormatName , $ value );
278+ $ value = $ this ->processParamsFormat ($ nestedFormatName , $ value );
285279 }
286280
287281 // this throws if the value is invalid
@@ -298,37 +292,37 @@ private function processParamsFormat(Request $request, string $format, ?array $v
298292
299293 /**
300294 * Calls either getPostField, getQueryField or getPathField based on the provided metadata.
301- * @param Request $request Request object holding the request data.
302295 * @param \App\Helpers\MetaFormats\RequestParamData $paramData Metadata of the request parameter.
303296 * @throws \App\Exceptions\InternalServerException Thrown when an unexpected parameter location was set.
304297 * @return mixed Returns the value from the request.
305298 */
306- private function getValueFromParamData (Request $ request , RequestParamData $ paramData ): mixed
299+ private function getValueFromParamData (RequestParamData $ paramData ): mixed
307300 {
308301 switch ($ paramData ->type ) {
309302 case Type::Post:
310- return $ this ->getPostField ($ request , $ paramData ->name , required: $ paramData ->required );
303+ return $ this ->getPostField ($ paramData ->name , required: $ paramData ->required );
311304 case Type::Query:
312- return $ this ->getQueryField ($ request , $ paramData ->name , required: $ paramData ->required );
305+ return $ this ->getQueryField ($ paramData ->name , required: $ paramData ->required );
313306 case Type::Path:
314- return $ this ->getPathField ($ request , $ paramData ->name );
307+ return $ this ->getPathField ($ paramData ->name );
315308 default :
316309 throw new InternalServerException ("Unknown parameter type: {$ paramData ->type ->name }" );
317310 }
318311 }
319312
320- private function getPostField (Request $ request , $ param , $ required = true )
313+ private function getPostField ($ param , $ required = true )
321314 {
322- $ post = $ request ->getPost ();
315+ $ req = $ this ->getRequest ();
316+ $ post = $ req ->getPost ();
323317
324- if ($ request ->isMethod ("POST " )) {
318+ if ($ req ->isMethod ("POST " )) {
325319 // nothing to see here...
326320 } else {
327- if ($ request ->isMethod ("PUT " ) || $ request ->isMethod ("DELETE " )) {
321+ if ($ req ->isMethod ("PUT " ) || $ req ->isMethod ("DELETE " )) {
328322 parse_str (file_get_contents ('php://input ' ), $ post );
329323 } else {
330324 throw new WrongHttpMethodException (
331- "Cannot get the post parameters in method ' " . $ request ->getMethod () . "'. "
325+ "Cannot get the post parameters in method ' " . $ req ->getMethod () . "'. "
332326 );
333327 }
334328 }
@@ -344,18 +338,18 @@ private function getPostField(Request $request, $param, $required = true)
344338 }
345339 }
346340
347- private function getQueryField (Request $ request , $ param , $ required = true )
341+ private function getQueryField ($ param , $ required = true )
348342 {
349- $ value = $ request ->getParameter ($ param );
343+ $ value = $ this -> getRequest () ->getParameter ($ param );
350344 if ($ value === null && $ required ) {
351345 throw new BadRequestException ("Missing required query field $ param " );
352346 }
353347 return $ value ;
354348 }
355349
356- private function getPathField (Request $ request , $ param )
350+ private function getPathField ($ param )
357351 {
358- $ value = $ request ->getParameter ($ param );
352+ $ value = $ this ->getParameter ($ param );
359353 if ($ value === null ) {
360354 throw new BadRequestException ("Missing required path field $ param " );
361355 }
0 commit comments