AbstractResponse
extends AbstractRequestResponse
in package
Abstract HTTP response class
Tags
Table of Contents
Properties
- $body : Body|null
- Body
- $code : int|null
- Response code
- $headers : array<string|int, mixed>
- Headers
- $message : string|null
- Response message
- $responseCodes : array<string|int, mixed>
- Response codes & messages
- $version : string
- HTTP version for response, i.e. 1.0, 1.1, 2.0, etc.
Methods
- __construct() : mixed
- Constructor
- __get() : mixed
- Magic method to get either the headers or body
- addHeader() : AbstractRequestResponse
- Add a header
- addHeaders() : AbstractRequestResponse
- Add all headers
- create() : static
- Factory method to create a Response object
- decodeBodyContent() : Body
- Decode the body
- getBody() : Body
- Get the body
- getBodyContent() : mixed
- Get body content
- getBodyContentLength() : int
- Get body content length
- getCode() : int
- Get the response code
- getHeader() : mixed
- Get a header
- getHeaderAsString() : mixed
- Get a header
- getHeaders() : array<string|int, mixed>
- Get all headers
- getHeadersAsArray() : array<string|int, mixed>
- Get all header values as associative array
- getHeadersAsString() : string
- Get all header values formatted string
- getHeaderValue() : mixed
- Get header value
- getHeaderValueAsString() : string|null
- Get header value as string
- getMessage() : string
- Get the response HTTP message
- getVersion() : string
- Get the response HTTP version
- hasBody() : bool
- Has a body
- hasBodyContent() : bool
- Has body content
- hasCode() : bool
- Has the response code
- hasHeader() : bool
- Has a header
- hasHeaders() : bool
- Determine if there are headers
- hasMessage() : bool
- Has the response message
- hasVersion() : bool
- Has the response HTTP version
- isAccepted() : bool
- Determine if the response is 202 accepted
- isBadGateway() : bool
- Determine if the response is a 502 Bad Gateway
- isBadRequest() : bool
- Determine if the response is a 400 Bad Request
- isClientError() : bool
- Determine if the response is a client error
- isConflict() : bool
- Determine if the response is a 409 Conflict
- isContinue() : bool
- Determine if the response is a 100 continue
- isCreated() : bool
- Determine if the response is 201 created
- isError() : bool
- Determine if the response is an error
- isForbidden() : bool
- Determine if the response is a 403 Forbidden
- isFound() : bool
- Determine if the response is a 302 Found
- isInternalServerError() : bool
- Determine if the response is a 500 Internal Server Error
- isLengthRequired() : bool
- Determine if the response is a 411 Length Required
- isMethodNotAllowed() : bool
- Determine if the response is a 405 Method Not Allowed
- isMovedPermanently() : bool
- Determine if the response is a 301 Moved Permanently
- isNoContent() : bool
- Determine if the response is 204 No Content
- isNotAcceptable() : bool
- Determine if the response is a 406 Not Acceptable
- isNotFound() : bool
- Determine if the response is a 404 Not Found
- isOk() : bool
- Determine if the response is 200 OK
- isRedirect() : bool
- Determine if the response is a redirect
- isRequestTimeout() : bool
- Determine if the response is a 408 Request Timeout
- isServerError() : bool
- Determine if the response is a server error
- isServiceUnavailable() : bool
- Determine if the response is a 503 Service Unavailable
- isSuccess() : bool
- Determine if the response is a success
- isTooManyRequests() : bool
- Determine if the response is a 429 Too Many Requests
- isUnauthorized() : bool
- Determine if the response is a 401 Unauthorized
- isUnprocessableEntity() : bool
- Determine if the response is a 422 Unprocessable Entity
- isUnsupportedMediaType() : bool
- Determine if the response is a 415 Unsupported Media Type
- removeBody() : AbstractRequestResponse
- Remove the body
- removeHeader() : AbstractRequestResponse
- Remove a header
- removeHeaders() : AbstractRequestResponse
- Remove all headers
- setBody() : AbstractRequestResponse
- Set the body
- setCode() : AbstractResponse
- Set the response code
- setHeaders() : AbstractRequestResponse
- Set all headers (clear out any existing headers)
- setMessage() : AbstractResponse
- Set the response message
- setVersion() : AbstractResponse
- Set the response version
Properties
$body
Body
protected
Body|null
$body
= null
$code
Response code
protected
int|null
$code
= null
$headers
Headers
protected
array<string|int, mixed>
$headers
= []
$message
Response message
protected
string|null
$message
= null
$responseCodes
Response codes & messages
protected
static array<string|int, mixed>
$responseCodes
= [
// Informational 1xx
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
// Success 2xx
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
207 => 'Multi-Status',
208 => 'Already Reported',
226 => 'IM Used',
// Redirection 3xx
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
306 => 'Switch Proxy',
307 => 'Temporary Redirect',
308 => 'Permanent Redirect',
// Client Error 4xx
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Payload Too Large',
414 => 'URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Range Not Satisfiable',
417 => 'Expectation Failed',
421 => 'Misdirected Request',
422 => 'Unprocessable Entity',
423 => 'Locked',
424 => 'Failed Dependency',
426 => 'Upgrade Required',
428 => 'Precondition Required',
429 => 'Too Many Requests',
431 => 'Request Header Fields Too Large',
451 => 'Unavailable For Legal Reasons',
// Server Error 5xx
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
506 => 'Variant Also Negotiates',
507 => 'Insufficient Storage',
508 => 'Loop Detected',
509 => 'Bandwidth Limit Exceeded',
510 => 'Not Extended',
511 => 'Network Authentication Required',
]
$version
HTTP version for response, i.e. 1.0, 1.1, 2.0, etc.
protected
string
$version
= '1.1'
Methods
__construct()
Constructor
public
__construct([array<string|int, mixed> $config = [] ]) : mixed
Instantiate the response object
Parameters
- $config : array<string|int, mixed> = []
__get()
Magic method to get either the headers or body
public
__get(string $name) : mixed
Parameters
- $name : string
addHeader()
Add a header
public
addHeader(Header|string|int $header[, string|null $value = null ]) : AbstractRequestResponse
Parameters
- $header : Header|string|int
- $value : string|null = null
Return values
AbstractRequestResponseaddHeaders()
Add all headers
public
addHeaders(array<string|int, mixed> $headers) : AbstractRequestResponse
Parameters
- $headers : array<string|int, mixed>
Return values
AbstractRequestResponsecreate()
Factory method to create a Response object
public
static create([array<string|int, mixed> $config = [] ]) : static
Parameters
- $config : array<string|int, mixed> = []
Return values
staticdecodeBodyContent()
Decode the body
public
decodeBodyContent([string|null $body = null ]) : Body
Parameters
- $body : string|null = null
Return values
BodygetBody()
Get the body
public
getBody() : Body
Return values
BodygetBodyContent()
Get body content
public
getBodyContent() : mixed
getBodyContentLength()
Get body content length
public
getBodyContentLength([bool $mb = false ]) : int
Parameters
- $mb : bool = false
Return values
intgetCode()
Get the response code
public
getCode() : int
Return values
intgetHeader()
Get a header
public
getHeader(string $name) : mixed
Parameters
- $name : string
getHeaderAsString()
Get a header
public
getHeaderAsString(string $name) : mixed
Parameters
- $name : string
getHeaders()
Get all headers
public
getHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>getHeadersAsArray()
Get all header values as associative array
public
getHeadersAsArray([bool $asStrings = true ]) : array<string|int, mixed>
Parameters
- $asStrings : bool = true
Return values
array<string|int, mixed>getHeadersAsString()
Get all header values formatted string
public
getHeadersAsString([mixed $status = null ][, string $eol = "
" ]) : string
Parameters
- $status : mixed = null
- $eol : string = " "
Return values
stringgetHeaderValue()
Get header value
public
getHeaderValue(string $name[, int $i = 0 ]) : mixed
Parameters
- $name : string
- $i : int = 0
getHeaderValueAsString()
Get header value as string
public
getHeaderValueAsString(string $name[, int $i = 0 ]) : string|null
Parameters
- $name : string
- $i : int = 0
Return values
string|nullgetMessage()
Get the response HTTP message
public
getMessage() : string
Return values
stringgetVersion()
Get the response HTTP version
public
getVersion() : string
Return values
stringhasBody()
Has a body
public
hasBody() : bool
Return values
boolhasBodyContent()
Has body content
public
hasBodyContent() : bool
Return values
boolhasCode()
Has the response code
public
hasCode() : bool
Return values
boolhasHeader()
Has a header
public
hasHeader(string $name) : bool
Parameters
- $name : string
Return values
boolhasHeaders()
Determine if there are headers
public
hasHeaders() : bool
Return values
boolhasMessage()
Has the response message
public
hasMessage() : bool
Return values
boolhasVersion()
Has the response HTTP version
public
hasVersion() : bool
Return values
boolisAccepted()
Determine if the response is 202 accepted
public
isAccepted() : bool
Return values
boolisBadGateway()
Determine if the response is a 502 Bad Gateway
public
isBadGateway() : bool
Return values
boolisBadRequest()
Determine if the response is a 400 Bad Request
public
isBadRequest() : bool
Return values
boolisClientError()
Determine if the response is a client error
public
isClientError() : bool
Return values
boolisConflict()
Determine if the response is a 409 Conflict
public
isConflict() : bool
Return values
boolisContinue()
Determine if the response is a 100 continue
public
isContinue() : bool
Return values
boolisCreated()
Determine if the response is 201 created
public
isCreated() : bool
Return values
boolisError()
Determine if the response is an error
public
isError() : bool
Return values
boolisForbidden()
Determine if the response is a 403 Forbidden
public
isForbidden() : bool
Return values
boolisFound()
Determine if the response is a 302 Found
public
isFound() : bool
Return values
boolisInternalServerError()
Determine if the response is a 500 Internal Server Error
public
isInternalServerError() : bool
Return values
boolisLengthRequired()
Determine if the response is a 411 Length Required
public
isLengthRequired() : bool
Return values
boolisMethodNotAllowed()
Determine if the response is a 405 Method Not Allowed
public
isMethodNotAllowed() : bool
Return values
boolisMovedPermanently()
Determine if the response is a 301 Moved Permanently
public
isMovedPermanently() : bool
Return values
boolisNoContent()
Determine if the response is 204 No Content
public
isNoContent() : bool
Return values
boolisNotAcceptable()
Determine if the response is a 406 Not Acceptable
public
isNotAcceptable() : bool
Return values
boolisNotFound()
Determine if the response is a 404 Not Found
public
isNotFound() : bool
Return values
boolisOk()
Determine if the response is 200 OK
public
isOk() : bool
Return values
boolisRedirect()
Determine if the response is a redirect
public
isRedirect() : bool
Return values
boolisRequestTimeout()
Determine if the response is a 408 Request Timeout
public
isRequestTimeout() : bool
Return values
boolisServerError()
Determine if the response is a server error
public
isServerError() : bool
Return values
boolisServiceUnavailable()
Determine if the response is a 503 Service Unavailable
public
isServiceUnavailable() : bool
Return values
boolisSuccess()
Determine if the response is a success
public
isSuccess() : bool
Return values
boolisTooManyRequests()
Determine if the response is a 429 Too Many Requests
public
isTooManyRequests() : bool
Return values
boolisUnauthorized()
Determine if the response is a 401 Unauthorized
public
isUnauthorized() : bool
Return values
boolisUnprocessableEntity()
Determine if the response is a 422 Unprocessable Entity
public
isUnprocessableEntity() : bool
Return values
boolisUnsupportedMediaType()
Determine if the response is a 415 Unsupported Media Type
public
isUnsupportedMediaType() : bool
Return values
boolremoveBody()
Remove the body
public
removeBody() : AbstractRequestResponse
Return values
AbstractRequestResponseremoveHeader()
Remove a header
public
removeHeader(string $name) : AbstractRequestResponse
Parameters
- $name : string
Return values
AbstractRequestResponseremoveHeaders()
Remove all headers
public
removeHeaders() : AbstractRequestResponse
Return values
AbstractRequestResponsesetBody()
Set the body
public
setBody(string|Body $body) : AbstractRequestResponse
Parameters
- $body : string|Body
Return values
AbstractRequestResponsesetCode()
Set the response code
public
setCode([int $code = 200 ]) : AbstractResponse
Parameters
- $code : int = 200
Tags
Return values
AbstractResponsesetHeaders()
Set all headers (clear out any existing headers)
public
setHeaders(array<string|int, mixed> $headers) : AbstractRequestResponse
Parameters
- $headers : array<string|int, mixed>
Return values
AbstractRequestResponsesetMessage()
Set the response message
public
setMessage([string|null $message = null ]) : AbstractResponse
Parameters
- $message : string|null = null
Return values
AbstractResponsesetVersion()
Set the response version
public
setVersion(float|string $version) : AbstractResponse
Parameters
- $version : float|string