Response
Response
Constants
TYPE_HTML
public const TYPE_HTML = 1TYPE_JSON
public const TYPE_JSON = 2TYPE_XML
public const TYPE_XML = 3TYPE_TEXT
public const TYPE_TEXT = 4TYPE_BINARY
public const TYPE_BINARY = 5TYPE_HAZAAR
public const TYPE_HAZAAR = 6Properties
encryptionKey
public string $encryptionKeyheaders
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(): voidgetResponseTypeName
public getResponseTypeName(int $type): stringParameters
| Parameter | Type | Description |
|---|---|---|
$type | int |
writeOutput
Writes the output content to the response.
public writeOutput(): voidThis method performs the following steps:
- Initializes the content to an empty string.
- Checks if the content has been modified and retrieves it if so.
- If an encryption key is set, encrypts the content using the default encryption cipher and sets the appropriate header.
- If the script is not running in CLI mode and headers have not been set, writes the headers.
- Outputs the content and flushes the output buffer.
setHeader
Sets a header for the response.
public setHeader(string $key, string $value, bool $overwrite = true): boolThis 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. |
setHeaders
Add multiple headers.
public setHeaders(array $headers, bool $overwrite = true): boolParameters
| Parameter | Type | Description |
|---|---|---|
$headers | array | |
$overwrite | bool |
removeHeader
Removes a header from the response.
public removeHeader(string $key): voidThis 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): stringParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key of the header to retrieve |
clearHeaders
Clears all the headers from the response.
public clearHeaders(): voidThis 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.
setContentType
Sets the content type for the response.
public setContentType(?string $type): voidIf 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(): stringsetContent
Sets the content for the response.
public setContent(mixed $content): voidParameters
| 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): voidParameters
| Parameter | Type | Description |
|---|---|---|
$content | mixed | the content to be added to the response |
setStatus
Sets the HTTP status code for the response.
public setStatus(int $status): voidParameters
| 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(): voidThis 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 Mon, 27 Oct 2025 13:01:29 +0000