Response
in package
implements
ResponseInterface
HTTP Response Provider
PHP Mini Framework
This class borrows heavily from the Symfony2 Framework and is part of the symfony package
Tags
Interfaces, Classes, Traits and Enums
- ResponseInterface
- PHP Mini Framework
Table of Contents
- $statusTexts : array<string|int, mixed>
- $body : StreamInterface|resource|string|null
- $httpHeaders : array<string|int, mixed>
- $parameters : array<string|int, mixed>
- $statusCode : int
- $statusText : string
- $version : string
- $clearBuffer : bool
- __construct() : mixed
- __toString() : string
- Converts the response object to string containing all headers and the response content.
- addHttpHeaders() : self
- addParameters() : self
- getBody() : StreamInterface|string
- getHttpHeader() : mixed
- getHttpHeaders() : array<string|int, mixed>
- getParameter() : mixed
- getParameters() : array<string|int, mixed>
- getResponseBody() : StreamInterface|string|null
- getStatusCode() : int
- getStatusText() : string
- html() : self
- isClientError() : bool
- isInformational() : bool
- isInvalid() : bool
- isRedirection() : bool
- isServerError() : bool
- isSuccessful() : bool
- json() : self
- redirect() : self
- Header Redirect
- send() : mixed
- setBody() : self
- setHttpHeader() : self
- setHttpHeaders() : self
- setParameter() : self
- setParameters() : self
- setStatusCode() : self
- toPsr() : ResponseInterface
- Create PSR7 Server response
- xml() : self
- buildHeader() : string
- Returns the build header line.
- beautifyCallback() : string
- Function from Symfony2 HttpFoundation - output pretty header
- beautifyHeaderName() : mixed
- Function from Symfony2 HttpFoundation - output pretty header
- getHttpHeadersAsString() : string
- Function from Symfony2 HttpFoundation - output pretty header
Properties
$statusTexts
public
static array<string|int, mixed>
$statusTexts
= array(100 => 'Continue', 101 => 'Switching Protocols', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use 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', 429 => 'Too Many Requests', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported')
Tags
$body
protected
StreamInterface|resource|string|null
$body
= NULL
Tags
$httpHeaders
protected
array<string|int, mixed>
$httpHeaders
= array()
Tags
$parameters
protected
array<string|int, mixed>
$parameters
= array()
Tags
$statusCode
protected
int
$statusCode
= 200
Tags
$statusText
protected
string
$statusText
Tags
$version
protected
string
$version
Tags
$clearBuffer
private
bool
$clearBuffer
= false
Tags
Methods
__construct()
public
__construct([array<string|int, mixed> $parameters = array() ][, int $statusCode = 200 ][, array<string|int, mixed> $headers = array() ]) : mixed
Parameters
- $parameters : array<string|int, mixed> = array()
- $statusCode : int = 200
- $headers : array<string|int, mixed> = array()
Tags
Return values
mixed —__toString()
Converts the response object to string containing all headers and the response content.
public
__toString() : string
Tags
Return values
string —The response with headers and content
addHttpHeaders()
public
addHttpHeaders(array<string|int, mixed> $httpHeaders) : self
Parameters
- $httpHeaders : array<string|int, mixed>
Tags
Return values
self —addParameters()
public
addParameters(array<string|int, mixed> $parameters) : self
Parameters
- $parameters : array<string|int, mixed>
Tags
Return values
self —getBody()
public
getBody() : StreamInterface|string
Tags
Return values
StreamInterface|string —getHttpHeader()
public
getHttpHeader(string $name[, mixed $default = null ]) : mixed
Parameters
- $name : string
- $default : mixed = null
Tags
Return values
mixed —getHttpHeaders()
public
getHttpHeaders() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —getParameter()
public
getParameter(string $name[, mixed $default = null ]) : mixed
Parameters
- $name : string
- $default : mixed = null
Tags
Return values
mixed —getParameters()
public
getParameters() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —getResponseBody()
public
getResponseBody([string $format = ResponseFormat::JSON ]) : StreamInterface|string|null
Parameters
- $format : string = ResponseFormat::JSON
-
@see \Busarm\PhpMini\Enums\ResponseFormat
Tags
Return values
StreamInterface|string|null —getStatusCode()
public
getStatusCode() : int
Tags
Return values
int —getStatusText()
public
getStatusText() : string
Tags
Return values
string —html()
public
html(StreamInterface|string|null $data[, int $code = 200 ][, bool $continue = false ]) : self
Parameters
- $data : StreamInterface|string|null
- $code : int = 200
-
response code
- $continue : bool = false
Tags
Return values
self —isClientError()
public
isClientError() : bool
Tags
Return values
bool —isInformational()
public
isInformational() : bool
Tags
Return values
bool —isInvalid()
public
isInvalid() : bool
Tags
Return values
bool —isRedirection()
public
isRedirection() : bool
Tags
Return values
bool —isServerError()
public
isServerError() : bool
Tags
Return values
bool —isSuccessful()
public
isSuccessful() : bool
Tags
Return values
bool —json()
public
json(array<string|int, mixed> $data[, int $code = 200 ][, bool $continue = false ]) : self
Parameters
- $data : array<string|int, mixed>
- $code : int = 200
-
response code
- $continue : bool = false
Tags
Return values
self —redirect()
Header Redirect
public
redirect(string $uri[, string $method = 'auto' ][, int $code = 307 ]) : self
Parameters
- $uri : string
-
URL
- $method : string = 'auto'
-
Redirect method. Eg. 'auto', 'location' or 'refresh'
- $code : int = 307
-
HTTP Response status code. E.g 307 or 302
Tags
Return values
self —send()
public
send([string $format = ResponseFormat::JSON ][, bool $continue = false ]) : mixed
Parameters
- $format : string = ResponseFormat::JSON
-
@see \Busarm\PhpMini\Enums\ResponseFormat
- $continue : bool = false
Tags
Return values
mixed —setBody()
public
setBody(StreamInterface|string $body) : self
Parameters
- $body : StreamInterface|string
Tags
Return values
self —setHttpHeader()
public
setHttpHeader(string $name, mixed $value) : self
Parameters
- $name : string
- $value : mixed
Tags
Return values
self —setHttpHeaders()
public
setHttpHeaders(array<string|int, mixed> $httpHeaders) : self
Parameters
- $httpHeaders : array<string|int, mixed>
Tags
Return values
self —setParameter()
public
setParameter(string $name, mixed $value) : self
Parameters
- $name : string
- $value : mixed
Tags
Return values
self —setParameters()
public
setParameters(array<string|int, mixed> $parameters) : self
Parameters
- $parameters : array<string|int, mixed>
Tags
Return values
self —setStatusCode()
public
setStatusCode(int $statusCode[, string $text = null ]) : self
Parameters
- $statusCode : int
- $text : string = null
Tags
Return values
self —toPsr()
Create PSR7 Server response
public
toPsr([string $format = ResponseFormat::JSON ]) : ResponseInterface
Parameters
- $format : string = ResponseFormat::JSON
-
@see \Busarm\PhpMini\Enums\ResponseFormat
Tags
Return values
ResponseInterface —xml()
public
xml(mixed $data[, int $code = 200 ][, bool $continue = false ]) : self
Parameters
- $data : mixed
- $code : int = 200
-
response code
- $continue : bool = false
Tags
Return values
self —buildHeader()
Returns the build header line.
protected
buildHeader(string $name, string $value) : string
Parameters
- $name : string
-
The header name
- $value : string
-
The header value
Tags
Return values
string —The built header line
beautifyCallback()
Function from Symfony2 HttpFoundation - output pretty header
private
beautifyCallback(array<string|int, mixed> $match) : string
Parameters
- $match : array<string|int, mixed>
Tags
Return values
string —beautifyHeaderName()
Function from Symfony2 HttpFoundation - output pretty header
private
beautifyHeaderName(string $name) : mixed
Parameters
- $name : string
Tags
Return values
mixed —getHttpHeadersAsString()
Function from Symfony2 HttpFoundation - output pretty header
private
getHttpHeadersAsString(array<string|int, mixed> $headers) : string
Parameters
- $headers : array<string|int, mixed>