class ResponseService (View source)

A collection of tools for the creation of responses.

Methods

__construct(RequestInterface $request, ViewService $view_service)

Constructor.

void
respond(ResponseInterface $response)

Send output based on a response object.

void
sendHeaders(ResponseInterface $response)

Send a request's headers to the client.

void
sendBody(ResponseInterface $response, integer $chunk_size = 4096)

Send a request's body to the client.

ResponseInterface
response()

Create a new response object.

ResponseInterface
output(string $output)

Get a cloned response with the passed string as the body.

ResponseInterface
json(mixed $data)

Get a cloned response, json encoding the passed data as the body.

redirect(RequestInterface $request = null)

Get a cloned response, with location and status headers.

ResponseInterface
error(integer $status)

Get an error response, with status headers and rendering a suitable view as the body.

Details

__construct(RequestInterface $request, ViewService $view_service)

Constructor.

Parameters

RequestInterface $request
ViewService $view_service

void respond(ResponseInterface $response)

Send output based on a response object.

Parameters

ResponseInterface $response

Return Value

void

void sendHeaders(ResponseInterface $response)

Send a request's headers to the client.

Parameters

ResponseInterface $response

Return Value

void

void sendBody(ResponseInterface $response, integer $chunk_size = 4096)

Send a request's body to the client.

Parameters

ResponseInterface $response
integer $chunk_size

Return Value

void

ResponseInterface response()

Create a new response object.

Return Value

ResponseInterface

ResponseInterface output(string $output)

Get a cloned response with the passed string as the body.

Parameters

string $output

Return Value

ResponseInterface

ResponseInterface json(mixed $data)

Get a cloned response, json encoding the passed data as the body.

Parameters

mixed $data

Return Value

ResponseInterface

RedirectResponse redirect(RequestInterface $request = null)

Get a cloned response, with location and status headers.

Parameters

RequestInterface $request

Return Value

RedirectResponse

ResponseInterface error(integer $status)

Get an error response, with status headers and rendering a suitable view as the body.

Parameters

integer $status

Return Value

ResponseInterface