Symfony2 API
Class

Symfony\Component\HttpFoundation\StreamedResponse

class StreamedResponse extends Response

StreamedResponse represents a streamed HTTP response.

A StreamedResponse uses a callback for its content.

The callback should use the standard PHP functions like echo
to stream the response back to the client. The flush() method
can also be used if needed.

Methods

__construct(mixed $callback = null, integer $status = 200, array $headers = array())

Constructor.

static Response create($callback = null, integer $status = 200, array $headers = array())

Factory method for chainability

setCallback(mixed $callback)

Sets the PHP callback associated with this Response.

Response prepare(Request $request)

Prepares the Response before it is sent to the client.

Response sendContent()

Sends content for the current web response.

Response setContent(mixed $content)

Sets the response content.

false getContent()

Gets the current response content.

Details

at line 43
public __construct(mixed $callback = null, integer $status = 200, array $headers = array())

Constructor.

Parameters

mixed $callback A valid PHP callback
integer $status The response status code
array $headers An array of response headers

Exceptions

InvalidArgumentException When the HTTP status code is not valid

at line 56
static public Response create($callback = null, integer $status = 200, array $headers = array())

Factory method for chainability

Example:

return Response::create($body, 200)
->setSharedMaxAge(300);

Parameters

$callback
integer $status The response status code
array $headers An array of response headers

Return Value

Response

at line 68
public setCallback(mixed $callback)

Sets the PHP callback associated with this Response.

Parameters

mixed $callback A valid PHP callback

Exceptions

LogicException

at line 79
public Response prepare(Request $request)

Prepares the Response before it is sent to the client.

This method tweaks the Response to ensure that it is
compliant with RFC 2616. Most of the changes are based on
the Request that is "associated" with this Response.

Parameters

Request $request A Request instance

Return Value

Response The current response.

at line 91
public Response sendContent()

Sends content for the current web response.

Return Value

Response

at line 111
public Response setContent(mixed $content)

Sets the response content.

Valid types are strings, numbers, and objects that implement a __toString() method.

Parameters

mixed $content

Return Value

Response

Exceptions

UnexpectedValueException

at line 123
public false getContent()

Gets the current response content.

Return Value

false Content