Documentation

AbstractResponse extends AbstractRequestResponse
in package

AbstractYes

Abstract HTTP response class

Tags
category

Pop

author

Nick Sagona, III dev@nolainteractive.com

copyright

Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)

license

http://www.popphp.org/license New BSD License

version
5.2.0

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

$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

create()

Factory method to create a Response object

public static create([array<string|int, mixed> $config = [] ]) : static
Parameters
$config : array<string|int, mixed> = []
Return values
static

decodeBodyContent()

Decode the body

public decodeBodyContent([string|null $body = null ]) : Body
Parameters
$body : string|null = null
Return values
Body

getBodyContentLength()

Get body content length

public getBodyContentLength([bool $mb = false ]) : int
Parameters
$mb : bool = false
Return values
int

getCode()

Get the response code

public getCode() : int
Return values
int

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
string

getHeaderValue()

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|null

getMessage()

Get the response HTTP message

public getMessage() : string
Return values
string

getVersion()

Get the response HTTP version

public getVersion() : string
Return values
string

hasCode()

Has the response code

public hasCode() : bool
Return values
bool

hasHeader()

Has a header

public hasHeader(string $name) : bool
Parameters
$name : string
Return values
bool

hasMessage()

Has the response message

public hasMessage() : bool
Return values
bool

hasVersion()

Has the response HTTP version

public hasVersion() : bool
Return values
bool

isAccepted()

Determine if the response is 202 accepted

public isAccepted() : bool
Return values
bool

isBadGateway()

Determine if the response is a 502 Bad Gateway

public isBadGateway() : bool
Return values
bool

isBadRequest()

Determine if the response is a 400 Bad Request

public isBadRequest() : bool
Return values
bool

isClientError()

Determine if the response is a client error

public isClientError() : bool
Return values
bool

isConflict()

Determine if the response is a 409 Conflict

public isConflict() : bool
Return values
bool

isContinue()

Determine if the response is a 100 continue

public isContinue() : bool
Return values
bool

isCreated()

Determine if the response is 201 created

public isCreated() : bool
Return values
bool

isError()

Determine if the response is an error

public isError() : bool
Return values
bool

isForbidden()

Determine if the response is a 403 Forbidden

public isForbidden() : bool
Return values
bool

isFound()

Determine if the response is a 302 Found

public isFound() : bool
Return values
bool

isInternalServerError()

Determine if the response is a 500 Internal Server Error

public isInternalServerError() : bool
Return values
bool

isLengthRequired()

Determine if the response is a 411 Length Required

public isLengthRequired() : bool
Return values
bool

isMethodNotAllowed()

Determine if the response is a 405 Method Not Allowed

public isMethodNotAllowed() : bool
Return values
bool

isMovedPermanently()

Determine if the response is a 301 Moved Permanently

public isMovedPermanently() : bool
Return values
bool

isNoContent()

Determine if the response is 204 No Content

public isNoContent() : bool
Return values
bool

isNotAcceptable()

Determine if the response is a 406 Not Acceptable

public isNotAcceptable() : bool
Return values
bool

isNotFound()

Determine if the response is a 404 Not Found

public isNotFound() : bool
Return values
bool

isOk()

Determine if the response is 200 OK

public isOk() : bool
Return values
bool

isRedirect()

Determine if the response is a redirect

public isRedirect() : bool
Return values
bool

isRequestTimeout()

Determine if the response is a 408 Request Timeout

public isRequestTimeout() : bool
Return values
bool

isServerError()

Determine if the response is a server error

public isServerError() : bool
Return values
bool

isServiceUnavailable()

Determine if the response is a 503 Service Unavailable

public isServiceUnavailable() : bool
Return values
bool

isSuccess()

Determine if the response is a success

public isSuccess() : bool
Return values
bool

isTooManyRequests()

Determine if the response is a 429 Too Many Requests

public isTooManyRequests() : bool
Return values
bool

isUnauthorized()

Determine if the response is a 401 Unauthorized

public isUnauthorized() : bool
Return values
bool

isUnprocessableEntity()

Determine if the response is a 422 Unprocessable Entity

public isUnprocessableEntity() : bool
Return values
bool

isUnsupportedMediaType()

Determine if the response is a 415 Unsupported Media Type

public isUnsupportedMediaType() : bool
Return values
bool

        
On this page

Search results