Closed akrabat closed 9 years ago
Playing with code, these are two options:
Implement Request::createFromEnvironment() See: https://github.com/slimphp/Slim/compare/slimphp:develop...akrabat:request-create-from-environment?expand=1
This simplifies the creation of the Request object in the Container, which may be a good thing in and of itself.
:+1: for option 1 — Request::createFromEnvironment()
I tend to agree, so have raised PR: #1278
for option 1, POST values are also part of HTTP body.
:+1: for option 1.
@akrabat is this fixed now?
Yes.
Consider this:
We know that the file upload won't be picked up until #1263 is merged.
However, the rest of the form fields in the POST data are also missing!
Reading http://php.net/manual/en/wrappers.php.php#wrappers.php.input, I found this nugget:
So...
getParsedBody()
has to use $_POST in this scenario. However, we don't have access to $_POST as it's not passed in via the constructor.From the PSR-7 interface docblock for
getParsedBody()
there's this too:We currently use the
php://input
stream rather than$_POST
so that we can auto-decode JSON and XML bodies which is quite a cool feature.How should we fix this?
The two options I can see are:
I don't like 1 at all as it's moving something that's intrinsic to the Request to outside of it and now the created of the Request object has to be aware of the content-type which just seems odd.
to implement 2, we'd have to change the
Request
's signature from:to say:
We can then update the mediaType parsers to do use $postData or $body as required.
Does anyone have a better idea?