Response
in package
implements
ResponseInterface, Stringable
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
- Stringable
Table of Contents
- $statusTexts : array<string|int, mixed>
- $body : StreamInterface|Stringable|resource|string|null
- $format : string
- $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
- download() : self
- fromPsr() : self
- Create response object from PSR7 response
- getBody() : StreamInterface|Stringable|resource|string|null
- getFormat() : string
- getHttpHeader() : mixed
- getHttpHeaders() : array<string|int, mixed>
- getParameter() : mixed
- getParameters() : array<string|int, mixed>
- getResponseBody() : StreamInterface|Stringable|resource|string|null
- getStatusCode() : int
- getStatusText() : string
- html() : self
- isClientError() : bool
- isInformational() : bool
- isInvalid() : bool
- isRedirection() : bool
- isServerError() : bool
- isSuccessful() : bool
- json() : self
- redirect() : self
- Set Redirect Headers
- send() : mixed
- setBody() : self
- setFormat() : ResponseInterface
- setHttpHeader() : self
- setHttpHeaders() : self
- setParameter() : self
- setParameters() : self
- setStatusCode() : self
- toPsr() : ResponseInterface
- Get PSR7 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|Stringable|resource|string|null
$body
= NULL
Tags
$format
protected
string
$format
= \Busarm\PhpMini\Enums\ResponseFormat::JSON
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([StreamInterface|Stringable|resource|string|array<string|int, mixed>|null $body = null ][, int $statusCode = 200 ][, array<string|int, mixed> $headers = array() ][, string $version = '1.1' ][, mixed $format = ResponseFormat::JSON ]) : mixed
Parameters
- $body : StreamInterface|Stringable|resource|string|array<string|int, mixed>|null = null
- $statusCode : int = 200
- $headers : array<string|int, mixed> = array()
- $version : string = '1.1'
- $format : mixed = ResponseFormat::JSON
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 —download()
public
download(StreamInterface|string|null $data[, string $name = null ][, bool $inline = false ][, string $contentType = null ]) : self
Parameters
- $data : StreamInterface|string|null
- $name : string = null
- $inline : bool = false
- $contentType : string = null
Tags
Return values
self —fromPsr()
Create response object from PSR7 response
public
static fromPsr(ResponseInterface $psr) : self
Parameters
- $psr : ResponseInterface
Tags
Return values
self —getBody()
public
getBody() : StreamInterface|Stringable|resource|string|null
Tags
Return values
StreamInterface|Stringable|resource|string|null —getFormat()
public
getFormat() : string
Tags
Return values
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() : StreamInterface|Stringable|resource|string|null
Tags
Return values
StreamInterface|Stringable|resource|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 ]) : self
Parameters
- $data : StreamInterface|string|null
- $code : int = 200
-
response code
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 ]) : self
Parameters
- $data : array<string|int, mixed>
- $code : int = 200
-
response code
Tags
Return values
self —redirect()
Set Redirect Headers
public
redirect(string $uri[, int|false $refresh = false ]) : self
Parameters
- $uri : string
-
URL
- $refresh : int|false = false
-
Refresh page timeout. False to disable refresh redirect
Tags
Return values
self —send()
public
send([bool $continue = false ]) : mixed
Parameters
- $continue : bool = false
Tags
Return values
mixed —setBody()
public
setBody(StreamInterface|Stringable|resource|string|null $body) : self
Parameters
- $body : StreamInterface|Stringable|resource|string|null
Tags
Return values
self —setFormat()
public
setFormat([string $format = ResponseFormat::JSON ]) : ResponseInterface
Parameters
- $format : string = ResponseFormat::JSON
Tags
Return values
ResponseInterface —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()
Get PSR7 response
public
toPsr() : ResponseInterface
Tags
Return values
ResponseInterface —xml()
public
xml(mixed $data[, int $code = 200 ]) : self
Parameters
- $data : mixed
- $code : int = 200
-
response code
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>