Response
in package
Table of Contents
Properties
- $body : mixed|string
- $httpVersion : string
- $instance : Response|null
- $statusCode : int
- $statusMessage : string
Methods
- getBody() : mixed
- Method used for retrieving response body data
- getInstance() : Response
- Method used for retrieving an instance of the Response class
- getStatusCode() : int
- Method used for retrieving HTTP status code for the response
- getStatusMessage() : string
- Method used for retrieving HTTP status message for the response
- json() : string|bool
- Private method for turning response body into json encoded string
- send() : Response
- Use to send the output back to the client
- setHttpVersion() : Response
- Method used for setting HTTP version in the response header
- setStatusCode() : Response
- Method used for setting HTTP status code in the response header
- setStatusMessage() : Response
- Method used for setting HTTP status message in the resposne header
- withBody() : Response
- Method used to set the response body data that will be returned with send method
- withHeader() : Response
- Method used for setting a key-value pair in the response header
- withStatus() : Response
- Method used to set the HTTP status code and message in the response header
- setHTTPStatus() : void
- Private method used to set the HTTP status on the response header
Properties
$body
private
static mixed|string
$body
= ""
HTTP response body content
$httpVersion
private
static string
$httpVersion
= "HTTP/1.1"
HTTP version to be sent in the response header
$instance
private
static Response|null
$instance
= NULL
Instance of the Response class
$statusCode
private
static int
$statusCode
= 200
HTTP status code to be sent in the response header
$statusMessage
private
static string
$statusMessage
= ""
HTTP status message to be sent in the response header
Methods
getBody()
Method used for retrieving response body data
public
static getBody() : mixed
Return values
mixed —Returns body data to be or that was already sent back
getInstance()
Method used for retrieving an instance of the Response class
public
static getInstance() : Response
Return values
Response —Returns an existing instance of itself or creates a new one
getStatusCode()
Method used for retrieving HTTP status code for the response
public
static getStatusCode() : int
Return values
int —Returns HTTP status code
getStatusMessage()
Method used for retrieving HTTP status message for the response
public
static getStatusMessage() : string
Return values
string —Returns HTTP status message
json()
Private method for turning response body into json encoded string
public
static json() : string|bool
Tags
Return values
string|bool —Returns a JSON encoded string on success or FALSE on failure
send()
Use to send the output back to the client
public
static send([array<string|int, mixed>|object|string $data = NULL ][, string $type = "JSON" ]) : Response
Parameters
- $data : array<string|int, mixed>|object|string = NULL
- $type : string = "JSON"
-
Type of response to be returned (ex JSON)
Tags
Return values
Response —Returns an instance of itself to allow method chaining
setHttpVersion()
Method used for setting HTTP version in the response header
public
static setHttpVersion(string $httpVersion) : Response
Parameters
- $httpVersion : string
-
HTTP version (ex HTTP/1.0 or HTTP/1.1)
Return values
Response —Returns an instance of itself to allow method chaining
setStatusCode()
Method used for setting HTTP status code in the response header
public
static setStatusCode(int $statusCode) : Response
Parameters
- $statusCode : int
-
HTTP status code
Return values
Response —Returns an instance of itself to allow method chaining
setStatusMessage()
Method used for setting HTTP status message in the resposne header
public
static setStatusMessage(string $statusMessage) : Response
Parameters
- $statusMessage : string
-
HTTP status message
Return values
Response —Returns an instance of itself to allow method chaining
withBody()
Method used to set the response body data that will be returned with send method
public
static withBody(array<string|int, mixed>|object|string $data) : Response
Parameters
- $data : array<string|int, mixed>|object|string
-
Body data to be set
Return values
Response —Returns an instance of itself to allow method chaining
withHeader()
Method used for setting a key-value pair in the response header
public
static withHeader(string|array<string|int, mixed>|object $key, mixed $value) : Response
Parameters
- $key : string|array<string|int, mixed>|object
-
Header key
- $value : mixed
-
Header value
Return values
Response —Returns an instance of itself to allow method chaining
withStatus()
Method used to set the HTTP status code and message in the response header
public
static withStatus(int $code, string $message) : Response
Parameters
- $code : int
-
HTTP status code to be sent back
- $message : string
-
HTTP status message to be sent back
Return values
Response —Returns an instance of itself to allow method chaining
setHTTPStatus()
Private method used to set the HTTP status on the response header
private
static setHTTPStatus([bool $replace = false ]) : void
Parameters
- $replace : bool = false
-
Indicated if the similar existing header value should be replaced on second one appended