8000 [HttpFoundation] Add create on StreamedResponse · symfony/symfony@076bd1e · GitHub
[go: up one dir, main page]

Skip to content

Commit 076bd1e

Browse files
committed
[HttpFoundation] Add create on StreamedResponse
1 parent ff13528 commit 076bd1e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Symfony/Component/HttpFoundation/StreamedResponse.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,25 @@ public function __construct($callback = null, $status = 200, $headers = array())
5050
$this->streamed = false;
5151
}
5252

53+
/**
54+
* {@inheritDoc}
55+
*/
56+
public static function create($callback = null, $status = 200, $headers = array())
57+
{
58+
return new static($callback, $status, $headers);
59+
}
60+
5361
/**
5462
* Sets the PHP callback associated with this Response.
5563
*
5664
* @param mixed $callback A valid PHP callback
5765
*/
5866
public function setCallback($callback)
5967
{
60-
$this->callback = $callback;
61-
if (!is_callable($this->callback)) {
68+
if (!is_callable($callback)) {
6269
throw new \LogicException('The Response callback must be a valid PHP callable.');
6370
}
71+
$this->callback = $callback;
6472
}
6573

6674
/**

tests/Symfony/Tests/Component/HttpFoundation/StreamedResponseTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,12 @@ public function testGetContent()
8686
$response = new StreamedResponse(function () { echo 'foo'; });
8787
$this->assertFalse($response->getContent());
8888
}
89+
90+
public function testCreate()
91+
{
92+
$response = StreamedResponse::create(function () {}, 204);
93+
94+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response);
95+
$this->assertEquals(204, $response->getStatusCode());
96+
}
8997
}

0 commit comments

Comments
 (0)
0