Skip to content

Commit 9f9b0f7

Browse files
dunglasfabpot
authored andcommitted
[HttpFoundation] Get response content as resource several times for PHP >= 5.6
1 parent cc749a6 commit 9f9b0f7

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,8 +1459,8 @@ public function isMethodSafe()
14591459
*/
14601460
public function getContent($asResource = false)
14611461
{
1462-
if (false === $this->content || (true === $asResource && null !== $this->content)) {
1463-
throw new \LogicException('getContent() can only be called once when using the resource return type.');
1462+
if (PHP_VERSION_ID < 50600 && (false === $this->content || (true === $asResource && null !== $this->content))) {
1463+
throw new \LogicException('getContent() can only be called once when using the resource return type and PHP below 5.6.');
14641464
}
14651465

14661466
if (true === $asResource) {

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,11 +929,40 @@ public function testGetContentReturnsResource()
929929
*/
930930
public function testGetContentCantBeCalledTwiceWithResources($first, $second)
931931
{
932+
if (PHP_VERSION_ID >= 50600) {
933+
$this->markTestSkipped('PHP >= 5.6 allows to open php://input several times.');
934+
}
935+
932936
$req = new Request();
933937
$req->getContent($first);
934938
$req->getContent($second);
935939
}
936940

941+
/**
942+
*
943+
* @dataProvider getContentCantBeCalledTwiceWithResourcesProvider
944+
*/
945+
public function testGetContentCanBeCalledTwiceWithResources($first, $second)
946+
{
947+
if (PHP_VERSION_ID < 50600) {
948+
$this->markTestSkipped('PHP < 5.6 does not allow to open php://input several times.');
949+
}
950+
951+
$req = new Request();
952+
$a = $req->getContent($first);
953+
$b = $req->getContent($second);
954+
955+
if ($first) {
956+
$a = stream_get_contents($a);
957+
}
958+
959+
if ($second) {
960+
$b = stream_get_contents($b);
961+
}
962+
963+
$this->assertEquals($a, $b);
964+
}
965+
937966
public function getContentCantBeCalledTwiceWithResourcesProvider()
938967
{
939968
return array(

0 commit comments

Comments
 (0)