Alpha Framework 4.0.0 API Documentation

Response
in package

A class to encapsulate a HTTP Response.

Tags
since
2.0
author

John Collins dev@alphaframework.org

license

http://www.opensource.org/licenses/bsd-license.php The BSD License

copyright

Copyright (c) 2021, John Collins (founder of Alpha Framework). All rights reserved.

Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the
following conditions are met:

* Redistributions of source code must retain the above
  copyright notice, this list of conditions and the
  following disclaimer.
* Redistributions in binary form must reproduce the above
  copyright notice, this list of conditions and the
  following disclaimer in the documentation and/or other
  materials provided with the distribution.
* Neither the name of the Alpha Framework nor the names
  of its contributors may be used to endorse or promote
  products derived from this software without specific
  prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Table of Contents

Properties

$body  : string
The body of the response.
$cookies  : array<string|int, mixed>
An associative array of HTTP cookies on this response.
$headers  : array<string|int, mixed>
An associative array of headers for the response.
$HTTPStatusCodes  : array<string|int, mixed>
Array of supported HTTP response codes.
$status  : int
The status code of the response.

Methods

__construct()  : mixed
Build the response.
getBody()  : string|null
Get the response body.
getContentLength()  : int
Get the content length of the response.
getCookie()  : mixed
Get the cookie matching the key provided.
getCookies()  : array<string|int, mixed>
Get all of the cookies for the response.
getHeader()  : mixed
Get the header matching the key provided.
getHeaders()  : array<string|int, mixed>
Get all of the headers for the response.
getStatus()  : int
Get the status code of the response.
getStatusMessage()  : string
Get the status message of the response.
redirect()  : void
Builds a redirect response.
send()  : void
Sends the current response to standard output before exiting the current process.
setBody()  : void
Set the response body.
setCookie()  : void
Set a cookie key/value tuple for the response.
setHeader()  : void
Set a header key/value tuple for the response.
setStatus()  : void
Set the status code of the response.

Properties

$body

The body of the response.

private string $body
Tags
since
2.0

$cookies

An associative array of HTTP cookies on this response.

private array<string|int, mixed> $cookies
Tags
since
2.0

$headers

An associative array of headers for the response.

private array<string|int, mixed> $headers
Tags
since
2.0

$HTTPStatusCodes

Array of supported HTTP response codes.

private array<string|int, mixed> $HTTPStatusCodes = array(100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-Status', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => 'Switch Proxy', 307 => 'Temporary Redirect', 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 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m a teapot', 422 => 'Unprocessable Entity', 423 => 'Locked', 424 => 'Failed Dependency', 425 => 'Unordered Collection', 426 => 'Upgrade Required', 449 => 'Retry With', 450 => 'Blocked by Windows Parental Controls', 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', 509 => 'Bandwidth Limit Exceeded', 510 => 'Not Extended')
Tags
since
2.0

$status

The status code of the response.

private int $status
Tags
since
2.0

Methods

__construct()

Build the response.

public __construct(int $status[, string $body = null ][, array<string|int, mixed> $headers = array() ]) : mixed
Parameters
$status : int

The HTTP status code of the response.

$body : string = null

The body of the response (optional).

$headers : array<string|int, mixed> = array()

The headers to set on the response (optional).

Tags
throws
IllegalArguementException

getBody()

Get the response body.

public getBody() : string|null
Tags
since
2.0
Return values
string|null

getContentLength()

Get the content length of the response.

public getContentLength() : int
Tags
since
2.0
Return values
int

getCookie()

Get the cookie matching the key provided.

public getCookie(string $key[, mixed $default = null ]) : mixed
Parameters
$key : string

The key to search for

$default : mixed = null

If key is not found, return this instead

Tags
since
2.0

getCookies()

Get all of the cookies for the response.

public getCookies() : array<string|int, mixed>
Tags
since
2.0
Return values
array<string|int, mixed>

getHeader()

Get the header matching the key provided.

public getHeader(string $key[, mixed $default = null ]) : mixed
Parameters
$key : string

The key to search for

$default : mixed = null

If key is not found, return this instead

Tags
since
2.0

getHeaders()

Get all of the headers for the response.

public getHeaders() : array<string|int, mixed>
Tags
since
2.0
Return values
array<string|int, mixed>

getStatus()

Get the status code of the response.

public getStatus() : int
Tags
since
2.0
Return values
int

getStatusMessage()

Get the status message of the response.

public getStatusMessage() : string
Return values
string

redirect()

Builds a redirect response.

public redirect(string $URL) : void
Parameters
$URL : string

The URL to redirect the client to.

Tags
throws
IllegalArguementException
since
2.0

send()

Sends the current response to standard output before exiting the current process.

public send() : void
Tags
since
2.0

setBody()

Set the response body.

public setBody(string $body) : void
Parameters
$body : string

The response body.

Tags
since
2.0

setCookie()

Set a cookie key/value tuple for the response.

public setCookie(string $cookie, string $value) : void
Parameters
$cookie : string

The cookie key name.

$value : string

The cookie value.

Tags
since
2.0

setHeader()

Set a header key/value tuple for the response.

public setHeader(string $header, string $value) : void
Parameters
$header : string

The header key name.

$value : string

The header value.

Tags
since
2.0

setStatus()

Set the status code of the response.

public setStatus(int $status) : void
Parameters
$status : int

The response code.

Tags
throws
IllegalArguementException
since
2.0

        
On this page

Search results