Support RFC7158 JSON body boolean
esetnik opened this issue · comments
According to https://datatracker.ietf.org/doc/html/rfc7158 it is possible to pass non-object and non-array types as json bodies. e.g. a json body containing only a primitive boolean value such as:
true
And this is supported by php's json_decode
function which returns a bool given an input like:
$result = json_decode('true');
But ServerRequest requires an array to be returned by json_decode
for the json media type.
Slim-Http/src/ServerRequest.php
Lines 56 to 63 in 90c44f2
That is correct, however if you look here:
Slim-Http/src/ServerRequest.php
Line 196 in 90c44f2
The reason is that the PSR-7 getParsedBody()
method can only return array|object|null
:
/**
* Retrieve any parameters provided in the request body.
*
* If the request Content-Type is either application/x-www-form-urlencoded
* or multipart/form-data, and the request method is POST, this method MUST
* return the contents of $_POST.
*
* Otherwise, this method may return any results of deserializing
* the request body content; as parsing returns structured content, the
* potential types MUST be arrays or objects only. A null value indicates
* the absence of body content.
*
* @return null|array|object The deserialized body parameters, if any.
* These will typically be an array or object.
*/
public function getParsedBody();