Response
Response
Properties
headers
protected array $headersheadersSet
protected bool $headersSetcontentType
protected string $contentType = 'text/plain'statusCode
protected int $statusCodecontent
protected string $contentMethods
__construct
public __construct(string $type = 'text/html', int $status = 501): voidParameters
| Parameter | Type | Description |
|---|---|---|
$type | string | |
$status | int |
__sleep
public __sleep(): voidwriteOutput
Outputs the response content and sends HTTP headers if applicable.
public writeOutput(): voidThis method checks if the response has been modified and retrieves the content. If not running in CLI mode and headers have not been set, it sends the headers. Throws a HeadersSent exception if headers have already been sent. Finally, it outputs the content and flushes the output buffer.
header
Sets a header for the response.
public header(string $key, string $value, bool $overwrite = true): selfThis method allows setting a header key-value pair for the response. If the header key is 'content-length', the method will return false and will not set the header. Otherwise, it will set the header based on the provided parameters.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the header key |
$value | string | the header value |
$overwrite | bool | Optional. Whether to overwrite the existing header value if the key already exists. Default is true. |
headers
Add multiple headers.
public headers(array $headers, bool $overwrite = true): selfParameters
| Parameter | Type | Description |
|---|---|---|
$headers | array | |
$overwrite | bool |
removeHeader
Removes a header from the response.
public removeHeader(string $key): selfThis method checks if a header with the specified key exists in the headers array. If it does, the header is removed.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key of the header to be removed |
getHeaders
Retrieves the headers associated with the response.
public getHeaders(): voidgetHeader
Retrieves the header value associated with the specified key.
public getHeader(string $key, null $): voidParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key of the header to retrieve |
$ | null |
clearHeaders
Clears all the headers from the response.
public clearHeaders(): selfThis method resets the headers array, effectively removing any headers that have been set previously. It is useful when you need to start with a clean slate for headers before setting new ones.
modified
Checks if the response has been modified.
public modified(): boolThis method determines if the response status code indicates that the content has been modified. A status code of 304 means "Not Modified", so this method returns true if the status code is anything other than 304.
contentType
Sets the content type for the response.
public contentType(?string $type): selfIf no content type is provided, it attempts to detect the MIME type of the current content using the finfo extension.
Parameters
| Parameter | Type | Description |
|---|---|---|
$type | string | The MIME type to set. If null, the MIME type will be auto-detected. |
getContentType
Retrieves the content type of the response.
public getContentType(): stringgetContent
Retrieves the content of the response.
public getContent(): stringcontent
Sets the content for the response.
public content(mixed $content): selfParameters
| Parameter | Type | Description |
|---|---|---|
$content | mixed | the content to be set for the response |
getContentLength
Retrieves the content length.
public getContentLength(): inthasContent
Checks if the response has content.
public hasContent(): booladdContent
Adds content to the response.
public addContent(mixed $content): selfParameters
| Parameter | Type | Description |
|---|---|---|
$content | mixed | the content to be added to the response |
status
Sets the HTTP status code for the response.
public status(int $status): selfParameters
| Parameter | Type | Description |
|---|---|---|
$status | int | the HTTP status code to set |
getStatus
Retrieves the current status code of the response.
public getStatus(): intgetStatusMessage
Retrieves the status message corresponding to the current HTTP status code.
public getStatusMessage(): stringThis method uses the http_response_text function to convert the status code stored in the $statusCode property to its associated textual representation.
ignoreHeaders
Marks the headers as set, effectively ignoring any further header modifications.
public ignoreHeaders(): selfThis method sets the internal flag $headersSet to true, which indicates that headers have already been sent or should be ignored. This can be useful in scenarios where you want to prevent any additional headers from being added to the response.
writeHeaders
Sets the HTTP response headers.
private writeHeaders(?int $contentLength): voidThis method sets the HTTP status code, content type, content length, and any additional headers specified in the $this->headers array. If the content length is not provided, it will be determined by the getContentLength method.
Parameters
| Parameter | Type | Description |
|---|---|---|
$contentLength | int | The length of the content. If null, it will be determined automatically. |
Generated by Hazaar API Doc Generator on Sun, 01 Mar 2026 09:22:26 +0000