I am refactoring my application using PSR-7 Requests using Slim3 as Router. On some of my entry points I have incoming GET and POST HTTP-Requests from external applications. Both GET and POST use the same parameter names. In the old code, a simple $_REQUEST
solved the issue, but I do not want to use the superglobals any longer.
For getting the parameters of the GET-Request, I use the following code:
$parameters = $request->getQueryParams();
For the POST-Request, I use:
$parameters = $request->getParsedBody();
Is there a PSR-7 function for solving the issue, or do I have to use array_merge()
each time?
Slim's request object has getParam()
and getParams()
which does what you want. These are not part of PSR-7 though.
In PSR-7 itself there is not a method on the request interface to do what you are asking for.
It could be possible that some implementation provides it, but I would find it odd.
If you can, the easiest possibility could be to extend the ServerResponseInterface implementation that you are using with a new method that does what you need.
In Slim
you could do this overriding the request
configuration key, providing your own request object