class ResponseService (View source)

A collection of tools for the creation of responses.

Methods

__construct(Request $request)

Constructor.

void
respond(ResponseInterface $response)

Send output based on a response object.

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()

Get a cloned response, with location and status headers.

view(string|string[] $views)

Get a view file representation.

ResponseInterface
error(integer $status)

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

Details

__construct(Request $request)

Constructor.

Parameters

Request $request

void respond(ResponseInterface $response)

Send output based on a response object.

Parameters

ResponseInterface $response

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()

Get a cloned response, with location and status headers.

Return Value

RedirectResponse

ViewInterface view(string|string[] $views)

Get a view file representation.

Parameters

string|string[] $views

Return Value

ViewInterface

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