Skip to content

Commit d16c63c

Browse files
committed
bug symfony#18 Allow multiple calls to Request::getContent() (aimeos)
This PR was squashed before being merged into the master branch (closes symfony#18). Discussion ---------- Allow multiple calls to Request::getContent() The Symfony request throws a LogicException if getContent() is called more than once and the first time with parameter "true". If $symfonyRequest->getContent(true) has thrown the exception, the call to $symfonyRequest->getContent() will do the same again. Commits ------- 9624b8b Allow multiple calls to Request::getContent()
2 parents 9c747c4 + 9624b8b commit d16c63c

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)