Aplus Framework Docs

Request extends Message
in package
implements RequestInterface

Class Request.

Tags
see
https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages#HTTP_Requests

Table of Contents

Interfaces

RequestInterface
Interface RequestInterface.

Properties

$auth  : array<string, string|null>|null
HTTP Authorization Header parsed.
$authType  : string|null
$body  : string
HTTP Message Body.
$cookies  : array<string, Cookie>
HTTP Message Cookies.
$files  : array<string, UploadedFile|array<string|int, mixed>>
$headers  : array<string, string>
HTTP Message Headers.
$host  : string
$id  : false|string
Request X-Request-ID header.
$isAjax  : bool
$isSecure  : bool
Tell if is a HTTPS connection.
$jsonFlags  : int
$method  : string
HTTP Request Method.
$negotiation  : array<string, array<string|int, mixed>|null>
$parsedBody  : array<string|int, mixed>|null
$port  : int
$protocol  : string
HTTP Message Protocol.
$referrer  : URL|false
$statusCode  : int
HTTP Response Status Code.
$url  : URL
HTTP Request URL.
$userAgent  : UserAgent|false

Methods

__call()  : static
__construct()  : mixed
Request constructor.
__toString()  : string
forceHttps()  : void
Force an HTTPS connection on same URL.
getAccepts()  : array<int, string>
Get the mime types of the Accept header.
getAuthType()  : string|null
Get the Authorization type.
getBasicAuth()  : array<string|int, string>|null
Get Basic authorization.
getBearerAuth()  : array<string|int, string>|null
Get Bearer authorization.
getBody()  : string
Get the Message body.
getCharsets()  : array<int, string>
Get the Accept-Charset's.
getContentType()  : string|null
Get the Content-Type header value.
getCookie()  : Cookie|null
Get a Cookie by name.
getCookies()  : array<string, Cookie>
Get all Cookies.
getDigestAuth()  : array<string|int, string>|null
Get Digest authorization.
getEncodings()  : array<int, string>
Get the Accept-Encoding.
getEnv()  : mixed
getFile()  : UploadedFile|null
getFiles()  : array<string, UploadedFile|array<string|int, mixed>>
getGet()  : mixed
Get the URL GET queries.
getHeader()  : string|null
getHeaderLine()  : string|null
getHeaderLines()  : array<int, string>
getHeaders()  : array<string, string>
getHost()  : string
getId()  : string|null
Get the X-Request-ID header.
getIp()  : string
Get the connection IP.
getJson()  : array<string, mixed>|false|stdClass
Get the request body as JSON.
getJsonFlags()  : int
Get JSON flags.
getLanguages()  : array<int, string>
Get the Accept-Language's.
getMethod()  : string
Gets the HTTP Request Method.
getParsedBody()  : array<string|int, mixed>|mixed|string|null
Get the Parsed Body or part of it.
getPatch()  : mixed
Get PATCH data.
getPort()  : int
Get the URL port.
getPost()  : mixed
Get POST data.
getProtocol()  : string
Get the HTTP protocol.
getPut()  : mixed
Get PUT data.
getRedirectData()  : mixed
Gets data from the last request, if it was redirected.
getReferer()  : URL|null
Get the Referer header.
getServer()  : mixed
Get $_SERVER variables.
getStartLine()  : string
Get the Message Start-Line.
getUrl()  : URL
Gets the requested URL.
getUserAgent()  : UserAgent|null
Gets the User Agent client.
hasCookie()  : bool
Say if the Message has a Cookie.
hasFiles()  : bool
hasHeader()  : bool
isAjax()  : bool
Check if is an AJAX Request based in the X-Requested-With Header.
isForm()  : bool
Tells if the Content-Type header is application/x-www-form-urlencoded or multipart/form-data.
isFormData()  : bool
Tells if the Content-Type header is multipart/form-data.
isFormUrlEncoded()  : bool
Tells if the Content-Type header is application/x-www-form-urlencoded.
isJson()  : bool
Say if the request is a JSON call.
isMethod()  : bool
isPost()  : bool
Say if the request method is POST.
isSecure()  : bool
Say if a connection has HTTPS.
makeResponse()  : Response
Make a Response with the current Request.
negotiateAccept()  : string
Negotiate the Accept header.
negotiateCharset()  : string
Negotiate the Accept-Charset.
negotiateEncoding()  : string
Negotiate the Accept-Encoding.
negotiateLanguage()  : string
Negotiated the Accept-Language.
parseQualityValues()  : array<string, float>
setJsonFlags()  : static
Set JSON flags.
appendHeader()  : static
Append a Message header.
filterInput()  : mixed
getInputFiles()  : array<string, UploadedFile|array<string|int, mixed>>
getMultipartBody()  : string
getNegotiableValues()  : array<int, string>
getStatusCode()  : int
Get the status code.
isStatusCode()  : bool
negotiate()  : string
parseAuth()  : array<string, string|null>
parseBasicAuth()  : array<string, string|null>
parseBearerAuth()  : array<string, string|null>
parseContentType()  : string|null
parseDigestAuth()  : array<string, string|null>
prepareCookies()  : void
prepareFiles()  : void
prepareHeaders()  : void
prepareStatusLine()  : void
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.
setHost()  : static
setMethod()  : static
Set the request method.
setProtocol()  : static
Set the HTTP protocol.
setStatusCode()  : static
setUrl()  : static
Set the Message URL.
setUserAgent()  : static
validateHost()  : void
Check if Host header is allowed.

Properties

$auth

HTTP Authorization Header parsed.

protected array<string, string|null>|null $auth = null

$authType

protected string|null $authType = null

Basic or Digest

$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 = []

$id

Request X-Request-ID header.

protected false|string $id

$isSecure

Tell if is a HTTPS connection.

protected bool $isSecure

$jsonFlags

protected int $jsonFlags = 0

$method

HTTP Request Method.

protected string $method

$negotiation

protected array<string, array<string|int, mixed>|null> $negotiation = ['ACCEPT' => null, 'CHARSET' => null, 'ENCODING' => null, 'LANGUAGE' => null]

$parsedBody

protected array<string|int, mixed>|null $parsedBody = null

$protocol

HTTP Message Protocol.

protected string $protocol = \Framework\HTTP\Protocol::HTTP_1_1

$statusCode

HTTP Response Status Code.

protected int $statusCode

Methods

__call()

public __call(string $method, array<int, mixed> $arguments) : static
Parameters
$method : string
$arguments : array<int, mixed>
Tags
throws
BadMethodCallException

for method not allowed or method not found

Return values
static

__construct()

Request constructor.

public __construct([array<string|int, string> $allowedHosts = [] ]) : mixed
Parameters
$allowedHosts : array<string|int, string> = []

set allowed hosts if your server don't serve by Host header, as Nginx do

Tags
throws
UnexpectedValueException

if invalid Host

__toString()

public __toString() : string
Attributes
#[Override]
Return values
string

forceHttps()

Force an HTTPS connection on same URL.

public forceHttps() : void

getAuthType()

Get the Authorization type.

public getAuthType() : string|null
Return values
string|null —

Basic, Bearer, Digest or null for none

getBasicAuth()

Get Basic authorization.

public getBasicAuth() : array<string|int, string>|null
Attributes
#[ArrayShape]
['username' => 'string|null', 'password' => 'string|null']
Return values
array<string|int, string>|null —

Two keys: username and password

getBearerAuth()

Get Bearer authorization.

public getBearerAuth() : array<string|int, string>|null
Attributes
#[ArrayShape]
['token' => 'string|null']
Return values
array<string|int, string>|null —

One key: token

getCookie()

Get a Cookie by name.

public getCookie(string $name) : Cookie|null
Parameters
$name : string
Return values
Cookie|null

getCookies()

Get all Cookies.

public getCookies() : array<string, Cookie>
Return values
array<string, Cookie>

getDigestAuth()

Get Digest authorization.

public getDigestAuth() : array<string|int, string>|null
Attributes
#[ArrayShape]
['username' => 'string|null', 'realm' => 'string|null', 'nonce' => 'string|null', 'uri' => 'string|null', 'response' => 'string|null', 'opaque' => 'string|null', 'qop' => 'string|null', 'nc' => 'string|null', 'cnonce' => 'string|null']
Return values
array<string|int, string>|null —

Nine keys: username, realm, nonce, uri, response, opaque, qop, nc, cnonce

getEnv()

public getEnv([string|null $name = null ][, int|null $filter = null ][, array<int, int>|int $filterOptions = 0 ]) : mixed
Parameters
$name : string|null = null
$filter : int|null = null
$filterOptions : array<int, int>|int = 0
Tags
see
Request::filterInput()

getGet()

Get the URL GET queries.

public getGet([string|null $name = null ][, int|null $filter = null ][, array<int, int>|int $filterOptions = 0 ]) : mixed
Parameters
$name : string|null = null
$filter : int|null = null
$filterOptions : array<int, int>|int = 0
Tags
see
Request::filterInput()

getHeader()

public getHeader(string $name) : string|null
Parameters
$name : string
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>
Return values
array<string, string>

getHost()

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

getId()

Get the X-Request-ID header.

public getId() : string|null
Return values
string|null

getIp()

Get the connection IP.

public getIp() : string
Return values
string

getJson()

Get the request body as JSON.

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

When true, JSON objects will be returned as associative arrays; when false, JSON objects will be returned as objects. When null, JSON objects will be returned as associative arrays or objects depending on whether JSON_OBJECT_AS_ARRAY is set in the flags.

$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

user specified recursion depth

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|stdClass —

If option JSON_THROW_ON_ERROR is not set, return false if json_decode fail. Otherwise, return a stdClass instance, or an array if the $associative argument is passed as true.

getJsonFlags()

Get JSON flags.

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

getMethod()

Gets the HTTP Request Method.

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

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

getParsedBody()

Get the Parsed Body or part of it.

public getParsedBody([string|null $name = null ][, int|null $filter = null ][, array<int, int>|int $filterOptions = 0 ]) : array<string|int, mixed>|mixed|string|null
Parameters
$name : string|null = null
$filter : int|null = null
$filterOptions : array<int, int>|int = 0
Tags
todo

https://php.watch/versions/8.4/request_parse_body

see
Request::filterInput()
Return values
array<string|int, mixed>|mixed|string|null

getPatch()

Get PATCH data.

public getPatch([string|null $name = null ][, int|null $filter = null ][, array<int, int>|int $filterOptions = 0 ]) : mixed
Parameters
$name : string|null = null
$filter : int|null = null
$filterOptions : array<int, int>|int = 0

getPort()

Get the URL port.

public getPort() : int
Return values
int

getPost()

Get POST data.

public getPost([string|null $name = null ][, int|null $filter = null ][, array<int, int>|int $filterOptions = 0 ]) : mixed
Parameters
$name : string|null = null
$filter : int|null = null
$filterOptions : array<int, int>|int = 0
Tags
see
Request::filterInput()

getProtocol()

Get the HTTP protocol.

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

getPut()

Get PUT data.

public getPut([string|null $name = null ][, int|null $filter = null ][, array<int, int>|int $filterOptions = 0 ]) : mixed
Parameters
$name : string|null = null
$filter : int|null = null
$filterOptions : array<int, int>|int = 0

getRedirectData()

Gets data from the last request, if it was redirected.

public getRedirectData([string|null $key = null ]) : mixed
Parameters
$key : string|null = null

a key name or null to get all data

Tags
see
Response::redirect()
throws
LogicException

if PHP Session is not active to get redirect data

Return values
mixed —

an array containing all data, the key value or null if the key was not found

getServer()

Get $_SERVER variables.

public getServer([string|null $name = null ][, int|null $filter = null ][, array<int, int>|int $filterOptions = 0 ]) : mixed
Parameters
$name : string|null = null
$filter : int|null = null
$filterOptions : array<int, int>|int = 0
Tags
see
Request::filterInput()

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

getUrl()

Gets the requested URL.

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

getUserAgent()

Gets the User Agent client.

public getUserAgent() : UserAgent|null
Return values
UserAgent|null —

the UserAgent object or null if no user-agent header was received

hasCookie()

Say if the Message has a Cookie.

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

Cookie name

Attributes
#[Pure]
Return values
bool

hasFiles()

public hasFiles() : bool
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

isAjax()

Check if is an AJAX Request based in the X-Requested-With Header.

public isAjax() : bool

The X-Requested-With Header containing the "XMLHttpRequest" value is used by various javascript libraries.

Return values
bool

isForm()

Tells if the Content-Type header is application/x-www-form-urlencoded or multipart/form-data.

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

isFormData()

Tells if the Content-Type header is multipart/form-data.

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

isFormUrlEncoded()

Tells if the Content-Type header is application/x-www-form-urlencoded.

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

isJson()

Say if the request is a JSON call.

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

isMethod()

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

for invalid method

Attributes
#[Override]
Return values
bool

isPost()

Say if the request method is POST.

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

isSecure()

Say if a connection has HTTPS.

public isSecure() : bool
Return values
bool

negotiateAccept()

Negotiate the Accept header.

public negotiateAccept(array<int, string> $negotiable) : string
Parameters
$negotiable : array<int, string>

Allowed mime types

Return values
string —

The negotiated mime type

negotiateCharset()

Negotiate the Accept-Charset.

public negotiateCharset(array<int, string> $negotiable) : string
Parameters
$negotiable : array<int, string>

Allowed charsets

Return values
string —

The negotiated charset

negotiateEncoding()

Negotiate the Accept-Encoding.

public negotiateEncoding(array<int, string> $negotiable) : string
Parameters
$negotiable : array<int, string>

The allowed encodings

Return values
string —

The negotiated encoding

negotiateLanguage()

Negotiated the Accept-Language.

public negotiateLanguage(array<int, string> $negotiable) : string
Parameters
$negotiable : array<int, string>

Allowed languages

Return values
string —

The negotiated language

setJsonFlags()

Set JSON flags.

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

getNegotiableValues()

protected getNegotiableValues(string $type) : array<int, string>
Parameters
$type : string
Return values
array<int, string>

getStatusCode()

Get the status code.

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

isStatusCode()

protected isStatusCode(int $code) : bool
Parameters
$code : int
Return values
bool

negotiate()

protected negotiate(string $type, array<int, string> $negotiable) : string
Parameters
$type : string
$negotiable : array<int, string>
Return values
string

parseAuth()

protected parseAuth(string $authorization) : array<string, string|null>
Parameters
$authorization : string
Return values
array<string, string|null>

parseBasicAuth()

protected parseBasicAuth(string $attributes) : array<string, string|null>
Parameters
$attributes : string
Attributes
#[ArrayShape]
['username' => 'string|null', 'password' => 'string|null']
#[Pure]
Return values
array<string, string|null>

parseBearerAuth()

protected parseBearerAuth(string $attributes) : array<string, string|null>
Parameters
$attributes : string
Attributes
#[ArrayShape]
['token' => 'string|null']
#[Pure]
Return values
array<string, string|null>

parseContentType()

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

parseDigestAuth()

protected parseDigestAuth(string $attributes) : array<string, string|null>
Parameters
$attributes : string
Attributes
#[ArrayShape]
['username' => 'string|null', 'realm' => 'string|null', 'nonce' => 'string|null', 'uri' => 'string|null', 'response' => 'string|null', 'opaque' => 'string|null', 'qop' => 'string|null', 'nc' => 'string|null', 'cnonce' => 'string|null']
Return values
array<string, string|null>

prepareCookies()

protected prepareCookies() : void

prepareFiles()

protected prepareFiles() : void

prepareHeaders()

protected prepareHeaders() : void

prepareStatusLine()

protected prepareStatusLine() : void

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

setHeaders()

Set a list of headers.

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

setHost()

protected setHost(string $host) : static
Parameters
$host : string
Tags
throws
InvalidArgumentException

for invalid host

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

setUrl()

Set the Message URL.

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

setUserAgent()

protected setUserAgent(UserAgent|string $userAgent) : static
Parameters
$userAgent : UserAgent|string
Return values
static

        
On this page

Search results