Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b1003d5

Browse filesBrowse files
committed
minor #14738 [HttpFoundation] Get response content as resource several times for PHP >= 5.6 (dunglas)
This PR was squashed before being merged into the 2.3 branch (closes #14738). Discussion ---------- [HttpFoundation] Get response content as resource several times for PHP >= 5.6 | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Since PHP 5.6, `php://input` can be opened several times. Commits ------- 9f9b0f7 [HttpFoundation] Get response content as resource several times for PHP >= 5.6
2 parents 662e281 + 9f9b0f7 commit b1003d5
Copy full SHA for b1003d5

File tree

Expand file treeCollapse file tree

2 files changed

+31
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+31
-2
lines changed

‎src/Symfony/Component/HttpFoundation/Request.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Request.php
+2-2Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
+29Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.