Skip to content

Commit d4ac4db

Browse files
committed
Merge pull request #1489 from akrabat/array-in-parsedbody
Return arrays where possible for getParsedBody()
2 parents c098a25 + 3fb0cd4 commit d4ac4db

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Slim/Http/Request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function __construct($method, UriInterface $uri, HeadersInterface $header
182182
}
183183

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

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

192192
$this->registerMediaTypeParser('application/x-www-form-urlencoded', function ($input) {
193193
parse_str($input, $data);
194-
return (object)$data;
194+
return $data;
195195
});
196196
}
197197

tests/Http/RequestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ public function testGetParsedBodyForm()
694694
$body = new RequestBody();
695695
$body->write('foo=bar');
696696
$request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
697-
$this->assertEquals((object)['foo' => 'bar'], $request->getParsedBody());
697+
$this->assertEquals(['foo' => 'bar'], $request->getParsedBody());
698698
}
699699

700700
public function testGetParsedBodyJson()
@@ -709,7 +709,7 @@ public function testGetParsedBodyJson()
709709
$body->write('{"foo":"bar"}');
710710
$request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
711711

712-
$this->assertEquals((object)['foo' => 'bar'], $request->getParsedBody());
712+
$this->assertEquals(['foo' => 'bar'], $request->getParsedBody());
713713
}
714714

715715
public function testGetParsedBodyXml()

0 commit comments

Comments
 (0)