Response Builder

The Response Builder allows you to create different responses to return from a controller action.

The easiest way to use the Response Builder is to make sure your Controllers extend Tomahawk\Routing\Controller. You then have access to it through $this->response.

Other wise just add the following parameter to the construct method of your Controller Tomahawk\HttpCore\ResponseBuilderInterface and it will get injected in through the Service Container.

Using The Response Builder


Create A Normal Response

The response returned is Symfony\Component\HttpFoundation\Response.

You pass the content, a status code (defaults to 200), and an array of headers (optional)

Create A Streamed Response

The response returned is Symfony\Component\HttpFoundation\StreamedResponse.

You pass a callback, a status code (defaults to 200), and an array of headers (optional)

Create A Redirect Response

The response returned is Symfony\Component\HttpFoundation\RedirectResponse.

You pass the URL, a status code (defaults to 302), and an array of headers (optional)

Create A Download Response

The response returned is Symfony\Component\HttpFoundation\BinaryFileResponse.

Create A JSON Response

The response returned is Symfony\Component\HttpFoundation\JsonResponse.

You pass an array of data, a status code (defaults to 200), and an array of headers (optional)