Request
extends Message
in package
implements
RequestInterface
Class Request.
Tags
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
= []
$files
protected
array<string, UploadedFile|array<string|int, mixed>>
$files
= []
$headers
HTTP Message Headers.
protected
array<string, string>
$headers
= []
$host
protected
string
$host
$id
Request X-Request-ID header.
protected
false|string
$id
$isAjax
protected
bool
$isAjax
$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
$port
protected
int
$port
$protocol
HTTP Message Protocol.
protected
string
$protocol
= \Framework\HTTP\Protocol::HTTP_1_1
$referrer
protected
URL|false
$referrer
$statusCode
HTTP Response Status Code.
protected
int
$statusCode
$url
HTTP Request URL.
protected
URL
$url
$userAgent
protected
UserAgent|false
$userAgent
Methods
__call()
public
__call(string $method, array<int, mixed> $arguments) : static
Parameters
- $method : string
- $arguments : array<int, mixed>
Tags
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
__toString()
public
__toString() : string
Attributes
- #[Override]
Return values
stringforceHttps()
Force an HTTPS connection on same URL.
public
forceHttps() : void
getAccepts()
Get the mime types of the Accept header.
public
getAccepts() : array<int, string>
Tags
Return values
array<int, string>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
getBody()
Get the Message body.
public
getBody() : string
Tags
Return values
stringgetCharsets()
Get the Accept-Charset's.
public
getCharsets() : array<int, string>
Tags
Return values
array<int, string>getContentType()
Get the Content-Type header value.
public
getContentType() : string|null
Tags
Attributes
- #[Pure]
Return values
string|nullgetCookie()
Get a Cookie by name.
public
getCookie(string $name) : Cookie|null
Parameters
- $name : string
Return values
Cookie|nullgetCookies()
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
getEncodings()
Get the Accept-Encoding.
public
getEncodings() : array<int, string>
Tags
Return values
array<int, string>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
getFile()
public
getFile(string $name) : UploadedFile|null
Parameters
- $name : string
Return values
UploadedFile|nullgetFiles()
public
getFiles() : array<string, UploadedFile|array<string|int, mixed>>
Return values
array<string, UploadedFile|array<string|int, mixed>>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
getHeader()
public
getHeader(string $name) : string|null
Parameters
- $name : string
Return values
string|nullgetHeaderLine()
public
getHeaderLine(string $name) : string|null
Parameters
- $name : string
Attributes
- #[Pure]
Return values
string|nullgetHeaderLines()
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
stringgetId()
Get the X-Request-ID header.
public
getId() : string|null
Return values
string|nullgetIp()
Get the connection IP.
public
getIp() : string
Return values
stringgetJson()
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
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
Return values
intgetLanguages()
Get the Accept-Language's.
public
getLanguages() : array<int, string>
Tags
Return values
array<int, string>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
Return values
array<string|int, mixed>|mixed|string|nullgetPatch()
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
intgetPost()
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
getProtocol()
Get the HTTP protocol.
public
getProtocol() : string
Attributes
- #[Pure]
Return values
stringgetPut()
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
Return values
mixed —an array containing all data, the key value or null if the key was not found
getReferer()
Get the Referer header.
public
getReferer() : URL|null
Tags
Return values
URL|nullgetServer()
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
getStartLine()
Get the Message Start-Line.
public
getStartLine() : string
Tags
Return values
stringgetUrl()
Gets the requested URL.
public
getUrl() : URL
Attributes
- #[Override]
- #[Pure]
Return values
URLgetUserAgent()
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
boolhasFiles()
public
hasFiles() : bool
Return values
boolhasHeader()
public
hasHeader(string $name[, string|null $value = null ]) : bool
Parameters
- $name : string
- $value : string|null = null
Attributes
- #[Pure]
Return values
boolisAjax()
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
boolisForm()
Tells if the Content-Type header is application/x-www-form-urlencoded or multipart/form-data.
public
isForm() : bool
Attributes
- #[Pure]
Return values
boolisFormData()
Tells if the Content-Type header is multipart/form-data.
public
isFormData() : bool
Attributes
- #[Pure]
Return values
boolisFormUrlEncoded()
Tells if the Content-Type header is application/x-www-form-urlencoded.
public
isFormUrlEncoded() : bool
Attributes
- #[Pure]
Return values
boolisJson()
Say if the request is a JSON call.
public
isJson() : bool
Attributes
- #[Pure]
Return values
boolisMethod()
public
isMethod(string $method) : bool
Parameters
- $method : string
Tags
Attributes
- #[Override]
Return values
boolisPost()
Say if the request method is POST.
public
isPost() : bool
Attributes
- #[Pure]
Return values
boolisSecure()
Say if a connection has HTTPS.
public
isSecure() : bool
Return values
boolmakeResponse()
Make a Response with the current Request.
public
makeResponse() : Response
Return values
ResponsenegotiateAccept()
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
parseQualityValues()
public
static parseQualityValues(string|null $string) : array<string, float>
Parameters
- $string : string|null
Tags
Return values
array<string, float>setJsonFlags()
Set JSON flags.
public
setJsonFlags(int $flags) : static
Parameters
- $flags : int
Tags
Return values
staticappendHeader()
Append a Message header.
protected
appendHeader(string $name, string $value) : static
Used to set repeated header field names.
Parameters
- $name : string
- $value : string
Tags
Return values
staticfilterInput()
protected
filterInput(int $type[, string|null $name = null ][, int|null $filter = null ][, array<int, int>|int $options = 0 ]) : mixed
Parameters
- $type : int
- $name : string|null = null
- $filter : int|null = null
- $options : array<int, int>|int = 0
Tags
getInputFiles()
protected
getInputFiles() : array<string, UploadedFile|array<string|int, mixed>>
Tags
Return values
array<string, UploadedFile|array<string|int, mixed>>getMultipartBody()
protected
getMultipartBody() : string
Tags
Return values
stringgetNegotiableValues()
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
intisStatusCode()
protected
isStatusCode(int $code) : bool
Parameters
- $code : int
Return values
boolnegotiate()
protected
negotiate(string $type, array<int, string> $negotiable) : string
Parameters
- $type : string
- $negotiable : array<int, string>
Return values
stringparseAuth()
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|nullparseDigestAuth()
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
staticremoveCookies()
Remove many Cookies by names.
protected
removeCookies(array<int, string> $names) : static
Parameters
- $names : array<int, string>
Return values
staticremoveHeader()
Remove a header by name.
protected
removeHeader(string $name) : static
Parameters
- $name : string
Return values
staticremoveHeaders()
Remove all headers.
protected
removeHeaders() : static
Return values
staticremoveHeadersByNames()
Remove headers by names.
protected
removeHeadersByNames(array<string|int, string> $names) : static
Parameters
- $names : array<string|int, string>
Return values
staticsetBody()
Set the Message body.
protected
setBody(string $body) : static
Parameters
- $body : string
Return values
staticsetCookie()
Set a new Cookie.
protected
setCookie(Cookie $cookie) : static
Parameters
- $cookie : Cookie
Return values
staticsetCookies()
Set a list of Cookies.
protected
setCookies(array<int, Cookie> $cookies) : static
Parameters
- $cookies : array<int, Cookie>
Return values
staticsetHeader()
Set a Message header.
protected
setHeader(string $name, string $value) : static
Parameters
- $name : string
- $value : string
Tags
Return values
staticsetHeaders()
Set a list of headers.
protected
setHeaders(array<string, string> $headers) : static
Parameters
- $headers : array<string, string>
Return values
staticsetHost()
protected
setHost(string $host) : static
Parameters
- $host : string
Tags
Return values
staticsetMethod()
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
Return values
staticsetProtocol()
Set the HTTP protocol.
protected
setProtocol(string $protocol) : static
Parameters
- $protocol : string
-
HTTP/1.1, HTTP/2, etc
Return values
staticsetStatusCode()
protected
setStatusCode(int $code) : static
Parameters
- $code : int
Return values
staticsetUrl()
Set the Message URL.
protected
setUrl(URL|string $url) : static
Parameters
- $url : URL|string
Return values
staticsetUserAgent()
protected
setUserAgent(UserAgent|string $userAgent) : static
Parameters
- $userAgent : UserAgent|string
Return values
staticvalidateHost()
Check if Host header is allowed.
protected
validateHost(array<string|int, string> $allowedHosts) : void
Parameters
- $allowedHosts : array<string|int, string>