Skip to content

Commit

Permalink
[HttpFoundation] Add create on StreamedResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Mar 15, 2012
1 parent ff13528 commit 076bd1e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Symfony/Component/HttpFoundation/StreamedResponse.php
Expand Up @@ -50,17 +50,25 @@ public function __construct($callback = null, $status = 200, $headers = array())
$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.
*
* @param mixed $callback A valid PHP callback
*/
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;
}

/**
Expand Down
Expand Up @@ -86,4 +86,12 @@ public function testGetContent()
$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());
}
}

0 comments on commit 076bd1e

Please sign in to comment.