8000 Allow multiple calls to Request::getContent() · symfony/symfony@9624b8b · GitHub
[go: up one dir, main page]

Skip to content

Commit 9624b8b

Browse files
aimeosdunglas
authored andcommitted
Allow multiple calls to Request::getContent()
1 parent ac5cd86 commit 9624b8b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Factory/DiactorosFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ public function createRequest(Request $symfonyRequest)
4545
$server = DiactorosRequestFactory::normalizeServer($symfonyRequest->server->all());
4646
$headers = $symfonyRequest->headers->all();
4747

48-
try {
49-
$body = new DiactorosStream($symfonyRequest->getContent(true));
50-
} catch (\LogicException $e) {
48+
if (PHP_VERSION_ID < 50600) {
5149
$body = new DiactorosStream('php://temp', 'wb+');
5250
$body->write($symfonyRequest->getContent());
51+
} else {
52+
$body = new DiactorosStream($symfonyRequest->getContent(true));
5353
}
5454

5555
$request = new ServerRequest(

Tests/Factory/DiactorosFactoryTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ public function testCreateRequest()
111111
$this->assertEquals(array('2.8'), $psrRequest->getHeader('X-Symfony'));
112112
}
113113

114+
public function testGetContentCanBeCalledAfterRequestCreation()
115+
{
116+
$header = array('HTTP_HOST' => 'dunglas.fr');
117+
$request = new Request(array(), array(), array(), array(), array(), $header, 'Content');
118+
119+
$psrRequest = $this->factory->createRequest($request);
120+
121+
$this->assertEquals('Content', $psrRequest->getBody()->__toString());
122+
$this->assertEquals('Content', $request->getContent());
123+
}
124+
114125
private function createUploadedFile($content, $originalName, $mimeType, $error)
115126
{
116127
$path = tempnam($this->tmpDir, uniqid());

0 commit comments

Comments
 (0)
0