Skip to content

Navigation Menu

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 df26630

Browse filesBrowse files
Ekmannicolas-grekas
authored andcommitted
Add support for streamed Symfony request
1 parent 81ae86d commit df26630
Copy full SHA for df26630

7 files changed

+27
-27
lines changed

‎Factory/DiactorosFactory.php

Copy file name to clipboardExpand all lines: Factory/DiactorosFactory.php
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ public function createRequest(Request $symfonyRequest)
8484
/**
8585
* Converts Symfony uploaded files array to the PSR one.
8686
*
87-
* @param array $uploadedFiles
88-
*
8987
* @return array
9088
*/
9189
private function getFiles(array $uploadedFiles)
@@ -110,8 +108,6 @@ private function getFiles(array $uploadedFiles)
110108
/**
111109
* Creates a PSR-7 UploadedFile instance from a Symfony one.
112110
*
113-
* @param UploadedFile $symfonyUploadedFile
114-
*
115111
* @return UploadedFileInterface
116112
*/
117113
private function createUploadedFile(UploadedFile $symfonyUploadedFile)

‎Factory/HttpFoundationFactory.php

Copy file name to clipboardExpand all lines: Factory/HttpFoundationFactory.php
+3-9Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(int $responseBufferMaxLength = 16372)
4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function createRequest(ServerRequestInterface $psrRequest)
46+
public function createRequest(ServerRequestInterface $psrRequest, bool $streamed = false)
4747
{
4848
$server = [];
4949
$uri = $psrRequest->getUri();
@@ -69,7 +69,7 @@ public function createRequest(ServerRequestInterface $psrRequest)
6969
$psrRequest->getCookieParams(),
7070
$this->getFiles($psrRequest->getUploadedFiles()),
7171
$server,
72-
$psrRequest->getBody()->__toString()
72+
$streamed ? $psrRequest->getBody()->detach() : $psrRequest->getBody()->__toString()
7373
);
7474
$request->headers->replace($psrRequest->getHeaders());
7575

@@ -79,8 +79,6 @@ public function createRequest(ServerRequestInterface $psrRequest)
7979
/**
8080
* Converts to the input array to $_FILES structure.
8181
*
82-
* @param array $uploadedFiles
83-
*
8482
* @return array
8583
*/
8684
private function getFiles(array $uploadedFiles)
@@ -101,8 +99,6 @@ private function getFiles(array $uploadedFiles)
10199
/**
102100
* Creates Symfony UploadedFile instance from PSR-7 ones.
103101
*
104-
* @param UploadedFileInterface $psrUploadedFile
105-
*
106102
* @return UploadedFile
107103
*/
108104
private function createUploadedFile(UploadedFileInterface $psrUploadedFile)
@@ -183,13 +179,11 @@ public function createResponse(ResponseInterface $psrResponse, bool $streamed =
183179
*
184180
* Some snippets have been taken from the Guzzle project: https://github.com/guzzle/guzzle/blob/5.3/src/Cookie/SetCookie.php#L34
185181
*
186-
* @param string $cookie
187-
*
188182
* @return Cookie
189183
*
190184
* @throws \InvalidArgumentException
191185
*/
192-
private function createCookie($cookie)
186+
private function createCookie(string $cookie)
193187
{
194188
foreach (explode(';', $cookie) as $part) {
195189
$part = trim($part);

‎Factory/PsrHttpFactory.php

Copy file name to clipboardExpand all lines: Factory/PsrHttpFactory.php
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ public function createRequest(Request $symfonyRequest)
7878
/**
7979
* Converts Symfony uploaded files array to the PSR one.
8080
*
81-
* @param array $uploadedFiles
82-
*
8381
* @return array
8482
*/
8583
private function getFiles(array $uploadedFiles)
@@ -104,8 +102,6 @@ private function getFiles(array $uploadedFiles)
104102
/**
105103
* Creates a PSR-7 UploadedFile instance from a Symfony one.
106104
*
107-
* @param UploadedFile $symfonyUploadedFile
108-
*
109105
* @return UploadedFileInterface
110106
*/
111107
private function createUploadedFile(UploadedFile $symfonyUploadedFile)

‎HttpFoundationFactoryInterface.php

Copy file name to clipboardExpand all lines: HttpFoundationFactoryInterface.php
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,14 @@ interface HttpFoundationFactoryInterface
2626
/**
2727
* Creates a Symfony Request instance from a PSR-7 one.
2828
*
29-
* @param ServerRequestInterface $psrRequest
30-
*
3129
* @return Request
3230
*/
33-
public function createRequest(ServerRequestInterface $psrRequest);
31+
public function createRequest(ServerRequestInterface $psrRequest, bool $streamed = false);
3432

3533
/**
3634
* Creates a Symfony Response instance from a PSR-7 one.
3735
*
38-
* @param ResponseInterface $psrResponse
39-
*
4036
* @return Response
4137
*/
42-
public function createResponse(ResponseInterface $psrResponse);
38+
public function createResponse(ResponseInterface $psrResponse, bool $streamed = false);
4339
}

‎HttpMessageFactoryInterface.php

Copy file name to clipboardExpand all lines: HttpMessageFactoryInterface.php
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,13 @@ interface HttpMessageFactoryInterface
2626
/**
2727
* Creates a PSR-7 Request instance from a Symfony one.
2828
*
29-
* @param Request $symfonyRequest
30-
*
3129
* @return ServerRequestInterface
3230
*/
3331
public function createRequest(Request $symfonyRequest);
3432

3533
/**
3634
* Creates a PSR-7 Response instance from a Symfony one.
3735
*
38-
* @param Response $symfonyResponse
39-
*
4036
* @return ResponseInterface
4137
*/
4238
public function createResponse(Response $symfonyResponse);

‎Tests/Factory/HttpFoundationFactoryTest.php

Copy file name to clipboardExpand all lines: Tests/Factory/HttpFoundationFactoryTest.php
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,27 @@ public function testCreateRequest()
8383
$this->assertEquals(['a', 'b'], $symfonyRequest->headers->get('X-data', null, false));
8484
}
8585

86+
public function testCreateRequestWithStreamedBody()
87+
{
88+
$serverRequest = new ServerRequest(
89+
'1.1',
90+
[],
91+
new Stream('The body'),
92+
'/',
93+
'GET',
94+
null,
95+
[],
96+
[],
97+
[],
98+
[],
99+
null,
100+
[]
101+
);
102+
103+
$symfonyRequest = $this->factory->createRequest($serverRequest, true);
104+
$this->assertEquals('The body', $symfonyRequest->getContent());
105+
}
106+
86107
public function testCreateRequestWithNullParsedBody()
87108
{
88109
$serverRequest = new ServerRequest(

‎Tests/Fixtures/Stream.php

Copy file name to clipboardExpand all lines: Tests/Fixtures/Stream.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function close()
3737

3838
public function detach()
3939
{
40+
return fopen('data://text/plain,'.$this->stringContent, 'r');
4041
}
4142

4243
public function getSize()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.