Responses

As Tomahawk wraps the Symfony Routing component you can return and Symfony Response.

Tomahawk also provides a response builder which allows you to quickly create different responses to return from a controller action.

The easiest way to use the Response Builder is 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)