Skip to content

Commit

Permalink
Return arrays where possible for getParsedBody()
Browse files Browse the repository at this point in the history
This fixes the weird case that if you POST, then getParsedBody() will
have an array in it ($_POST), but if you PUT or have json, then
getParsedBody() will have an object.

Even more weirdly, if you POST with the hidden _METHOD=PUT, you get an
array in your put() handler, but if you PUT to it you get an object.

It's much more consistent to try to always make it an array and ensures
that we can also handle keys with hyphens much more sanely as they are
horrible to deal with when in a stdClass.
  • Loading branch information
akrabat committed Sep 5, 2015
1 parent faaf470 commit 919ce21
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Slim/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function __construct($method, UriInterface $uri, HeadersInterface $header
}

$this->registerMediaTypeParser('application/json', function ($input) {
return json_decode($input);
return json_decode($input, true);
});

$this->registerMediaTypeParser('application/xml', function ($input) {
Expand All @@ -191,7 +191,7 @@ public function __construct($method, UriInterface $uri, HeadersInterface $header

$this->registerMediaTypeParser('application/x-www-form-urlencoded', function ($input) {
parse_str($input, $data);
return (object)$data;
return $data;
});
}

Expand Down

0 comments on commit 919ce21

Please sign in to comment.