Response
Response
Properties
encryptionKey
public string $encryptionKey
headers
protected array $headers
headersSet
protected bool $headersSet
contentType
protected string $contentType
statusCode
protected int $statusCode
Methods
__construct
public __construct({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$type | string | |
$status | int |
__sleep
public __sleep({Array})
writeOutput
Writes the output content to the response.
public writeOutput({Array})
This 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({Array})
This 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})
Parameters
Parameter | Type | Description |
---|---|---|
$headers | array | |
$overwrite | bool |
removeHeader
Removes a header from the response.
public removeHeader({Array})
This 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({Array})
getHeader
Retrieves the header value associated with the specified key.
public getHeader({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the key of the header to retrieve |
clearHeaders
Clears all the headers from the response.
public clearHeaders({Array})
This 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({Array})
This 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({Array})
If 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({Array})
getContent
Retrieves the content of the response.
public getContent({Array})
setContent
Sets the content for the response.
public setContent({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$content | mixed | the content to be set for the response |
getContentLength
Retrieves the content length.
public getContentLength({Array})
hasContent
Checks if the response has content.
public hasContent({Array})
addContent
Adds content to the response.
public addContent({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$content | mixed | the content to be added to the response |
setStatus
Sets the HTTP status code for the response.
public setStatus({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$status | int | the HTTP status code to set |
getStatus
Retrieves the current status code of the response.
public getStatus({Array})
getStatusMessage
Retrieves the status message corresponding to the current HTTP status code.
public getStatusMessage({Array})
This 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({Array})
This 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({Array})
This 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 |
---|---|---|
$content_length | int | The length of the content. If null, it will be determined automatically. |
Generated by Hazaar API Doc Generator