Aplus Framework Docs

Response extends Message
in package
implements ResponseInterface

Class Response.

Table of Contents

Interfaces

ResponseInterface
Interface ResponseInterface.

Properties

$body  : string
HTTP Message Body.
$cookies  : array<string, Cookie>
HTTP Message Cookies.
$headers  : array<string, string>
HTTP Message Headers.
$info  : array<string|int, mixed>
Response curl info.
$jsonFlags  : int
$method  : string
HTTP Request Method.
$protocol  : string
HTTP Message Protocol.
$request  : Request
$statusCode  : int
HTTP Response Status Code.
$statusReason  : string
$url  : URL
HTTP Request URL.

Methods

__construct()  : mixed
Response constructor.
__toString()  : string
getBody()  : string
Get the Message body.
getCookie()  : Cookie|null
Get a Cookie by name.
getCookies()  : array<string, Cookie>
Get all Cookies.
getHeader()  : string|null
getHeaderLine()  : string|null
getHeaderLines()  : array<int, string>
getHeaders()  : array<string, string>
getInfo()  : array<string|int, mixed>
getJson()  : array<string, mixed>|false|object
Get body as decoded JSON.
getJsonFlags()  : int
Get JSON flags.
getLinks()  : array<string, string>
Get parsed Link header as array.
getProtocol()  : string
Get the HTTP protocol.
getRequest()  : Request
getStartLine()  : string
Get the Message Start-Line.
getStatus()  : string
getStatusCode()  : int
Get the status code.
getStatusReason()  : string
hasCookie()  : bool
Say if the Message has a Cookie.
hasHeader()  : bool
isJson()  : bool
isStatusCode()  : bool
parseQualityValues()  : array<string, float>
setJsonFlags()  : static
Set JSON flags.
appendHeader()  : static
Append a Message header.
getMethod()  : string
Gets the HTTP Request Method.
getUrl()  : URL
Gets the requested URL.
isMethod()  : bool
parseContentType()  : string|null
parseLinkHeader()  : array<string, string>
removeCookie()  : static
Remove a Cookie by name.
removeCookies()  : static
Remove many Cookies by names.
removeHeader()  : static
Remove a header by name.
removeHeaders()  : static
Remove all headers.
removeHeadersByNames()  : static
Remove headers by names.
setBody()  : static
Set the Message body.
setCookie()  : static
Set a new Cookie.
setCookies()  : static
Set a list of Cookies.
setHeader()  : static
Set a Message header.
setHeaders()  : static
Set a list of headers.
setMethod()  : static
Set the request method.
setProtocol()  : static
Set the HTTP protocol.
setStatusCode()  : static
setStatusReason()  : static
setUrl()  : static
Set the Message URL.

Properties

$body

HTTP Message Body.

protected string $body

$cookies

HTTP Message Cookies.

protected array<string, Cookie> $cookies = []

$headers

HTTP Message Headers.

protected array<string, string> $headers = []

$info

Response curl info.

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

$method

HTTP Request Method.

protected string $method

$protocol

HTTP Message Protocol.

protected string $protocol

$statusCode

HTTP Response Status Code.

protected int $statusCode

$statusReason

protected string $statusReason

Methods

__construct()

Response constructor.

public __construct(Request $request, string $protocol, int $status, string $reason, array<string, array<int, string>> $headers, string $body[, array<string|int, mixed> $info = [] ]) : mixed
Parameters
$request : Request
$protocol : string
$status : int
$reason : string
$headers : array<string, array<int, string>>
$body : string
$info : array<string|int, mixed> = []

__toString()

public __toString() : string
Return values
string

getBody()

Get the Message body.

public getBody() : string
Attributes
#[Pure]
Return values
string

getCookie()

Get a Cookie by name.

public getCookie(string $name) : Cookie|null
Parameters
$name : string
Attributes
#[Pure]
Return values
Cookie|null

getCookies()

Get all Cookies.

public getCookies() : array<string, Cookie>
Attributes
#[Pure]
Return values
array<string, Cookie>

getHeader()

public getHeader(string $name) : string|null
Parameters
$name : string
Attributes
#[Pure]
Return values
string|null

getHeaderLine()

public getHeaderLine(string $name) : string|null
Parameters
$name : string
Attributes
#[Pure]
Return values
string|null

getHeaderLines()

public getHeaderLines() : array<int, string>
Attributes
#[Pure]
Return values
array<int, string>

getHeaders()

public getHeaders() : array<string, string>
Attributes
#[Pure]
Return values
array<string, string>

getInfo()

public getInfo() : array<string|int, mixed>
Attributes
#[ArrayShape]
['appconnect_time_us' => 'int', 'certinfo' => 'array', 'connect_time' => 'float', 'connect_time_us' => 'int', 'content_type' => 'string', 'download_content_length' => 'float', 'effective_method' => 'string', 'filetime' => 'int', 'header_size' => 'int', 'http_code' => 'int', 'http_version' => 'int', 'local_ip' => 'string', 'local_port' => 'int', 'namelookup_time' => 'float', 'namelookup_time_us' => 'int', 'pretransfer_time' => 'float', 'pretransfer_time_us' => 'int', 'primary_ip' => 'string', 'primary_port' => 'int', 'protocol' => 'int', 'redirect_count' => 'int', 'redirect_time' => 'float', 'redirect_time_us' => 'int', 'redirect_url' => 'string', 'request_size' => 'int', 'scheme' => 'string', 'size_download' => 'float', 'size_upload' => 'float', 'speed_download' => 'float', 'speed_upload' => 'float', 'ssl_verify_result' => 'int', 'ssl_verifyresult' => 'int', 'starttransfer_time' => 'float', 'starttransfer_time_us' => 'int', 'total_time' => 'float', 'total_time_us' => 'int', 'upload_content_length' => 'float', 'url' => 'string']
Return values
array<string|int, mixed>

getJson()

Get body as decoded JSON.

public getJson([bool $assoc = false ][, int|null $flags = null ][, int<1, max> $depth = 512 ]) : array<string, mixed>|false|object
Parameters
$assoc : bool = false
$flags : int|null = null

[optional]

Bitmask consisting of JSON_BIGINT_AS_STRING, JSON_INVALID_UTF8_IGNORE, JSON_INVALID_UTF8_SUBSTITUTE, JSON_OBJECT_AS_ARRAY, JSON_THROW_ON_ERROR.

Default is none when null.

$depth : int<1, max> = 512
Tags
see
https://www.php.net/manual/en/function.json-decode.php
https://www.php.net/manual/en/json.constants.php
Return values
array<string, mixed>|false|object

getJsonFlags()

Get JSON flags.

public getJsonFlags() : int
Tags
since
5.6
Return values
int

Get parsed Link header as array.

public getLinks() : array<string, string>

NOTE: To be parsed, links must be in the GitHub REST API format.

see
https://docs.github.com/en/rest/guides/using-pagination-in-the-rest-api#using-link-headers
https://docs.aplus-framework.com/guides/libraries/pagination/index.html#http-header-link
https://datatracker.ietf.org/doc/html/rfc5988
Return values
array<string, string> —

Associative array with rel as keys and links as values

getProtocol()

Get the HTTP protocol.

public getProtocol() : string
Attributes
#[Pure]
Return values
string

getStartLine()

Get the Message Start-Line.

public getStartLine() : string
Tags
throws
BadMethodCallException

if $this is not an instance of RequestInterface or ResponseInterface

Return values
string

getStatus()

public getStatus() : string
Attributes
#[Pure]
Return values
string

getStatusCode()

Get the status code.

public getStatusCode() : int
Attributes
#[Override]
#[Pure]
Return values
int

getStatusReason()

public getStatusReason() : string
Attributes
#[Pure]
Return values
string

hasCookie()

Say if the Message has a Cookie.

public hasCookie(string $name) : bool
Parameters
$name : string

Cookie name

Attributes
#[Pure]
Return values
bool

hasHeader()

public hasHeader(string $name[, string|null $value = null ]) : bool
Parameters
$name : string
$value : string|null = null
Attributes
#[Pure]
Return values
bool

isJson()

public isJson() : bool
Attributes
#[Pure]
Return values
bool

isStatusCode()

public isStatusCode(int $code) : bool
Parameters
$code : int
Tags
throws
InvalidArgumentException

if status code is invalid

Attributes
#[Override]
Return values
bool

setJsonFlags()

Set JSON flags.

public setJsonFlags(int $flags) : static
Parameters
$flags : int
Tags
since
5.6
Return values
static

getMethod()

Gets the HTTP Request Method.

protected getMethod() : string
Attributes
#[Pure]
Return values
string —

$method One of: CONNECT, DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT, or TRACE

getUrl()

Gets the requested URL.

protected getUrl() : URL
Attributes
#[Pure]
Return values
URL

isMethod()

protected isMethod(string $method) : bool
Parameters
$method : string
Tags
throws
InvalidArgumentException

for invalid method

Return values
bool

parseContentType()

protected parseContentType() : string|null
Attributes
#[Pure]
Return values
string|null

parseLinkHeader()

protected parseLinkHeader(string $headerLink) : array<string, string>
Parameters
$headerLink : string
Return values
array<string, string>

removeCookie()

Remove a Cookie by name.

protected removeCookie(string $name) : static
Parameters
$name : string
Return values
static

removeCookies()

Remove many Cookies by names.

protected removeCookies(array<int, string> $names) : static
Parameters
$names : array<int, string>
Return values
static

removeHeader()

Remove a header by name.

protected removeHeader(string $name) : static
Parameters
$name : string
Return values
static

removeHeaders()

Remove all headers.

protected removeHeaders() : static
Return values
static

removeHeadersByNames()

Remove headers by names.

protected removeHeadersByNames(array<string|int, string> $names) : static
Parameters
$names : array<string|int, string>
Return values
static

setBody()

Set the Message body.

protected setBody(string $body) : static
Parameters
$body : string
Return values
static

setCookie()

Set a new Cookie.

protected setCookie(Cookie $cookie) : static
Parameters
$cookie : Cookie
Return values
static

setCookies()

Set a list of Cookies.

protected setCookies(array<int, Cookie> $cookies) : static
Parameters
$cookies : array<int, Cookie>
Return values
static

setHeader()

Set a Message header.

protected setHeader(string $name, string $value) : static
Parameters
$name : string
$value : string
Tags
throws
Exception

if Cookie::setExpires fail

Attributes
#[Override]
Return values
static

setHeaders()

Set a list of headers.

protected setHeaders(array<string, string> $headers) : static
Parameters
$headers : array<string, string>
Return values
static

setMethod()

Set the request method.

protected setMethod(string $method) : static
Parameters
$method : string

One of: CONNECT, DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT, or TRACE

Tags
throws
InvalidArgumentException

for invalid method

Return values
static

setProtocol()

Set the HTTP protocol.

protected setProtocol(string $protocol) : static
Parameters
$protocol : string

HTTP/1.1, HTTP/2, etc

Return values
static

setStatusCode()

protected setStatusCode(int $code) : static
Parameters
$code : int
Return values
static

setStatusReason()

protected setStatusReason(string $statusReason) : static
Parameters
$statusReason : string
Return values
static

setUrl()

Set the Message URL.

protected setUrl(URL|string $url) : static
Parameters
$url : URL|string
Return values
static

        
On this page

Search results