Response
Response
Controller helper for building typed response objects.
class Response implements \Hazaar\Controller\Interface\HelperImplements: Hazaar\Controller\Interface\Helper
Exposes convenience factory methods for common response classes (HTML, JSON, XML, files, redirects, and status responses) so controllers can create consistent framework responses with minimal boilerplate.
Methods
ok
Creates a basic HTTP 200 OK response object.
public ok(): OKReturns: Hazaar\Controller\Response\HTTP\OK
file
Creates and returns a new File instance.
public file(File|string $file, ?Manager $manager): FileReturns: Hazaar\Controller\Response\File
Parameters
| Parameter | Type | Description |
|---|---|---|
$file | Hazaar\Controller\Response\File | string |
$manager | Hazaar\File\Manager | optional manager instance to associate with the file |
html
Generates an HTML response with the given content and HTTP status code.
public html(string $content, int $status = 200): HTMLReturns: Hazaar\Controller\Response\HTML
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | the HTML content to be returned in the response |
$status | int | the HTTP status code for the response (default is 200) |
image
Creates and returns a new Image instance.
public image(string $filename, int $quality = 8, ?Manager $manager): ImageReturns: Hazaar\Controller\Response\Image
Parameters
| Parameter | Type | Description |
|---|---|---|
$filename | string | the path to the image file |
$quality | int | the quality setting for the image (default is 8) |
$manager | Hazaar\File\Manager | optional image manager instance |
json
Returns a JSON response with the given data and HTTP status code.
public json(array|\JsonSerializable|\stdClass $data, int $status = 200): JSONReturns: Hazaar\Controller\Response\JSON
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | array | JsonSerializable |
$status | int | the HTTP status code for the response (default is 200) |
Creates and returns a new PDF response.
public PDF(string $file, bool $downloadable = true): PDFReturns: Hazaar\Controller\Response\PDF
Parameters
| Parameter | Type | Description |
|---|---|---|
$file | string | the path to the PDF file to be served |
$downloadable | bool | Optional. Whether the PDF should be downloaded by the client (default: true). |
text
Creates a new Text response with the given content and HTTP status code.
public text(string $content, int $status = 200): TextReturns: Hazaar\Controller\Response\Text
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | the text content to be sent in the response |
$status | int | the HTTP status code for the response (default is 200) |
view
Creates and returns a new View instance with the specified name. public function xml(Element $content, int $status = 200): XML
public view(string $name): ViewReturns: Hazaar\Controller\Response\View
{ return new XML($content, $status); }.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the view to instantiate |
xml
Generates an XML response with the given content and HTTP status code.
public xml(Element $content, int $status = 200): XMLReturns: Hazaar\Controller\Response\XML
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | Hazaar\XML\Element | the XML content to include in the response |
$status | int | the HTTP status code for the response (default is 200) |
redirect
Generate a redirect response to redirect the browser.
public redirect(string|URL $location): RedirectReturns: Hazaar\Controller\Response\HTTP\Redirect
It's quite common to redirect the user to an alternative URL. This may be to forward the request to another website, forward them to an authentication page or even just remove processed request parameters from the URL to neaten the URL up.
Parameters
| Parameter | Type | Description |
|---|---|---|
$location | string | Hazaar\HTTP\URL |
shutdown
public shutdown(ControllerResponse $response): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$response | Hazaar\Controller\Response |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000