merged branch Seldaek/chainableresp (PR #3606)

Commits
-------

3297f75 Fix header override
076bd1e [HttpFoundation] Add create on StreamedResponse

Discussion
----------

Chainable response

Fixed feedback from #3605
This commit is contained in:
Fabien Potencier 2012-03-15 19:10:35 +01:00
commit 5631002cd0
3 changed files with 20 additions and 4 deletions

View File

@ -27,7 +27,7 @@ class RedirectResponse extends Response
*
* @param string $url The URL to redirect to
* @param integer $status The status code (302 by default)
* @param array $headers The headers (Location is added with the given url)
* @param array $headers The headers (Location is always set to the given url)
*
* @see http://tools.ietf.org/html/rfc2616#section-10.3
*
@ -55,7 +55,7 @@ class RedirectResponse extends Response
</body>
</html>', htmlspecialchars($url, ENT_QUOTES, 'UTF-8')),
$status,
array_merge(array('Location' => $url), $headers)
array_merge($headers, array('Location' => $url))
);
if (!$this->isRedirect()) {

View File

@ -50,6 +50,14 @@ class StreamedResponse extends Response
$this->streamed = false;
}
/**
* {@inheritDoc}
*/
public static function create($callback = null, $status = 200, $headers = array())
{
return new static($callback, $status, $headers);
}
/**
* Sets the PHP callback associated with this Response.
*
@ -57,10 +65,10 @@ class StreamedResponse extends Response
*/
public function setCallback($callback)
{
$this->callback = $callback;
if (!is_callable($this->callback)) {
if (!is_callable($callback)) {
throw new \LogicException('The Response callback must be a valid PHP callable.');
}
$this->callback = $callback;
}
/**

View File

@ -86,4 +86,12 @@ class StreamedResponseTest extends \PHPUnit_Framework_TestCase
$response = new StreamedResponse(function () { echo 'foo'; });
$this->assertFalse($response->getContent());
}
public function testCreate()
{
$response = StreamedResponse::create(function () {}, 204);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response);
$this->assertEquals(204, $response->getStatusCode());
}
}