Documentation

Response extends AbstractResponse
in package

HTTP response class

Tags
category

Pop

author

Nick Sagona, III dev@nolainteractive.com

copyright

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

license

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

version
4.1.0

Table of Contents

$body  : Body
Body
$code  : int
Response code
$headers  : array<string|int, mixed>
Headers
$message  : string
Response message
$responseCodes  : array<string|int, mixed>
Response codes & messages
$version  : string
HTTP version for response, i.e. 1.0, 1.1, 2.0, 3.0, etc.
__construct()  : mixed
Constructor
__get()  : mixed
Magic method to get either the headers or body
__toString()  : string
Return entire response as a string
addHeader()  : AbstractHttp
Add a header
addHeaders()  : AbstractHttp
Add all headers
decodeBodyContent()  : Body
Decode the body
getBody()  : Body
Get the body
getBodyContent()  : mixed
Get body content
getCode()  : string
Get the response code
getHeader()  : 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 the response headers as a string
getHeaderValue()  : mixed
Get header value
getMessage()  : string
Get the response HTTP message
getMessageFromCode()  : string
Get response message from code
getVersion()  : float|string
Get the response HTTP version
hasBody()  : bool
Has a body
hasBodyContent()  : bool
Has body content
hasHeader()  : bool
Has a header
hasHeaders()  : bool
Determine if there are headers
isClientError()  : bool
Determine if the response is a client error
isError()  : bool
Determine if the response is an error
isRedirect()  : bool
Determine if the response is a redirect
isServerError()  : bool
Determine if the response is a server error
isSuccess()  : bool
Determine if the response is a success
prepareBody()  : string
Prepare response body
redirect()  : void
Send redirect
redirectAndExit()  : void
Send redirect and exit
removeBody()  : AbstractHttp
Remove the body
removeHeader()  : AbstractHttp
Remove a header
removeHeaders()  : AbstractHttp
Remove all headers
send()  : void
Send full response
sendAndExit()  : void
Send full response and exit
sendHeaders()  : void
Send response headers
setBody()  : AbstractHttp
Set the body
setCode()  : AbstractResponse
Set the response code
setMessage()  : AbstractResponse
Set the response message
setVersion()  : AbstractResponse
Set the response version

Properties

$headers

Headers

protected array<string|int, mixed> $headers = []

$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, 3.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> = []
Return values
mixed

__get()

Magic method to get either the headers or body

public __get(string $name) : mixed
Parameters
$name : string
Return values
mixed

__toString()

Return entire response as a string

public __toString() : string
Return values
string

decodeBodyContent()

Decode the body

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

getBodyContent()

Get body content

public getBodyContent() : mixed
Return values
mixed

getCode()

Get the response code

public getCode() : string
Return values
string

getHeader()

Get a header

public getHeader(string $name) : mixed
Parameters
$name : string
Return values
mixed

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() : array<string|int, mixed>
Return values
array<string|int, mixed>

getHeadersAsString()

Get the response headers as a string

public getHeadersAsString([bool $status = null ][, string $eol = " " ]) : string
Parameters
$status : bool = null
$eol : string = " "
Return values
string

getHeaderValue()

Get header value

public getHeaderValue(string $name) : mixed
Parameters
$name : string
Return values
mixed

getMessage()

Get the response HTTP message

public getMessage() : string
Return values
string

getMessageFromCode()

Get response message from code

public static getMessageFromCode(int $code) : string
Parameters
$code : int
Tags
throws
Exception
Return values
string

getVersion()

Get the response HTTP version

public getVersion() : float|string
Return values
float|string

hasBody()

Has a body

public hasBody() : bool
Return values
bool

hasBodyContent()

Has body content

public hasBodyContent() : bool
Return values
bool

hasHeader()

Has a header

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

hasHeaders()

Determine if there are headers

public hasHeaders() : bool
Return values
bool

isClientError()

Determine if the response is a client error

public isClientError() : bool
Return values
bool

isError()

Determine if the response is an error

public isError() : bool
Return values
bool

isRedirect()

Determine if the response is a redirect

public isRedirect() : bool
Return values
bool

isServerError()

Determine if the response is a server error

public isServerError() : bool
Return values
bool

isSuccess()

Determine if the response is a success

public isSuccess() : bool
Return values
bool

prepareBody()

Prepare response body

public prepareBody([bool $length = false ][, bool $mb = false ]) : string
Parameters
$length : bool = false
$mb : bool = false
Return values
string

redirect()

Send redirect

public static redirect(string $url[, string $code = '302' ][, string $version = '1.1' ]) : void
Parameters
$url : string
$code : string = '302'
$version : string = '1.1'
Tags
throws
Exception
Return values
void

redirectAndExit()

Send redirect and exit

public static redirectAndExit(string $url[, string $code = '302' ][, string $version = '1.1' ]) : void
Parameters
$url : string
$code : string = '302'
$version : string = '1.1'
Return values
void

send()

Send full response

public send([int $code = null ][, array<string|int, mixed> $headers = null ][, bool $length = false ]) : void
Parameters
$code : int = null
$headers : array<string|int, mixed> = null
$length : bool = false
Return values
void

sendAndExit()

Send full response and exit

public sendAndExit([int $code = null ][, array<string|int, mixed> $headers = null ][, bool $length = false ]) : void
Parameters
$code : int = null
$headers : array<string|int, mixed> = null
$length : bool = false
Return values
void

sendHeaders()

Send response headers

public sendHeaders() : void
Tags
throws
Exception
Return values
void

Search results