Request
A class to encapsulate a HTTP request.
Tags
Table of Contents
- $body : string
- The request body if one was provided.
- $cookies : array<string|int, mixed>
- An associative array of HTTP cookies on this request.
- $files : array<string|int, mixed>
- An associative 3D array of uploaded files.
- $headers : array<string|int, mixed>
- An associative array of HTTP headers on this request.
- $host : string
- The host header provided on the request.
- $HTTPMethods : array<string|int, mixed>
- Array of supported HTTP methods.
- $IP : string
- The IP of the client making the request.
- $method : string
- The HTTP method of this request (must be in HTTPMethods array).
- $params : array<string|int, mixed>
- The HTTP params (form data and query string) on this request.
- $queryString : string
- The query string provided on the request (if any).
- $URI : string
- The URI requested.
- __construct() : mixed
- Builds up the request based on available PHP super globals, in addition to any overrides provided (useful for testing).
- addParams() : mixed
- Append the hash array provided to the params for this request.
- getAccept() : string
- Get the Accept header of the request.
- getBody() : string
- Get the request body if one was provided.
- getContentLength() : string
- Get the Content-Length header of the request.
- getContentType() : string
- Get the Content-Type header of the request.
- getCookie() : mixed
- Get the cookie matching the key provided.
- getCookies() : array<string|int, mixed>
- Return all cookies on this request.
- getFile() : mixed
- Get the file matching the key provided.
- getFiles() : array<string|int, mixed>
- Return all files on this request.
- getHeader() : string
- Get the header matching the key provided.
- getHeaders() : array<string|int, mixed>
- Return all headers on this request.
- getHost() : string
- Get the host name of the client that sent the request.
- getIP() : string
- Get the IP address of the client that sent the request.
- getMethod() : string
- Get the HTTP method of this request.
- getParam() : string
- Get the param matching the key provided.
- getParams() : array<string|int, mixed>
- Return all params on this request.
- getQueryString() : string
- Get the query string provided on the request.
- getReferrer() : string
- Get the Referrer header of the request.
- getURI() : string
- Get the URI that was requested.
- getURL() : string
- Get the URL that was requested.
- getUserAgent() : string
- Get the User-Agent header of the request.
- isSecureURI() : bool
- Checks to see if the request contains a secure/encrypted token.
- parseParamsFromRoute() : mixed
- Parses the route provided to extract matching params of the route from this request's URI.
- setMethod() : mixed
- Set the HTTP method of this request.
- setParams() : mixed
- Set the params array.
- getGlobalBody() : string
- Attempts to get the raw body of the current request from super globals.
- getGlobalHeaders() : array<string|int, mixed>
- Tries to get the current HTTP request headers from super globals.
- getGlobalServerValue() : string
- Tries to get the requested param from the $_SERVER super global, otherwise returns an empty string.
Properties
$body
The request body if one was provided.
private
string
$body
Tags
$cookies
An associative array of HTTP cookies on this request.
private
array<string|int, mixed>
$cookies
Tags
$files
An associative 3D array of uploaded files.
private
array<string|int, mixed>
$files
Tags
$headers
An associative array of HTTP headers on this request.
private
array<string|int, mixed>
$headers
Tags
$host
The host header provided on the request.
private
string
$host
Tags
$HTTPMethods
Array of supported HTTP methods.
private
array<string|int, mixed>
$HTTPMethods
= array('HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'TRACE')
Tags
$IP
The IP of the client making the request.
private
string
$IP
Tags
$method
The HTTP method of this request (must be in HTTPMethods array).
private
string
$method
Tags
$params
The HTTP params (form data and query string) on this request.
private
array<string|int, mixed>
$params
Tags
$queryString
The query string provided on the request (if any).
private
string
$queryString
Tags
$URI
The URI requested.
private
string
$URI
Tags
Methods
__construct()
Builds up the request based on available PHP super globals, in addition to any overrides provided (useful for testing).
public
__construct([array<string|int, mixed> $overrides = array() ]) : mixed
Parameters
- $overrides : array<string|int, mixed> = array()
-
Hash array of PHP super globals to override
Tags
Return values
mixed —addParams()
Append the hash array provided to the params for this request.
public
addParams(mixed $params) : mixed
Parameters
- $params : mixed
Tags
Return values
mixed —getAccept()
Get the Accept header of the request.
public
getAccept() : string
Tags
Return values
string —getBody()
Get the request body if one was provided.
public
getBody() : string
Tags
Return values
string —getContentLength()
Get the Content-Length header of the request.
public
getContentLength() : string
Tags
Return values
string —getContentType()
Get the Content-Type header of the request.
public
getContentType() : string
Tags
Return values
string —getCookie()
Get the cookie matching the key provided.
public
getCookie(string $key[, mixed $default = null ]) : mixed
Parameters
- $key : string
-
The key to search for
- $default : mixed = null
-
If key is not found, return this instead
Tags
Return values
mixed —getCookies()
Return all cookies on this request.
public
getCookies() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —getFile()
Get the file matching the key provided.
public
getFile(string $key[, mixed $default = null ]) : mixed
Parameters
- $key : string
-
The key to search for
- $default : mixed = null
-
If key is not found, return this instead
Tags
Return values
mixed —getFiles()
Return all files on this request.
public
getFiles() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —getHeader()
Get the header matching the key provided.
public
getHeader(string $key[, mixed $default = null ]) : string
Parameters
- $key : string
-
The key to search for
- $default : mixed = null
-
If key is not found, return this instead
Tags
Return values
string —getHeaders()
Return all headers on this request.
public
getHeaders() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —getHost()
Get the host name of the client that sent the request.
public
getHost() : string
Tags
Return values
string —getIP()
Get the IP address of the client that sent the request.
public
getIP() : string
Tags
Return values
string —getMethod()
Get the HTTP method of this request.
public
getMethod() : string
Tags
Return values
string —getParam()
Get the param matching the key provided.
public
getParam(string $key[, mixed $default = null ]) : string
Parameters
- $key : string
-
The key to search for
- $default : mixed = null
-
If key is not found, return this instead
Tags
Return values
string —getParams()
Return all params on this request.
public
getParams() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —getQueryString()
Get the query string provided on the request.
public
getQueryString() : string
Tags
Return values
string —getReferrer()
Get the Referrer header of the request.
public
getReferrer() : string
Tags
Return values
string —getURI()
Get the URI that was requested.
public
getURI() : string
Tags
Return values
string —getURL()
Get the URL that was requested.
public
getURL() : string
Tags
Return values
string —getUserAgent()
Get the User-Agent header of the request.
public
getUserAgent() : string
Tags
Return values
string —isSecureURI()
Checks to see if the request contains a secure/encrypted token.
public
isSecureURI() : bool
Tags
Return values
bool —parseParamsFromRoute()
Parses the route provided to extract matching params of the route from this request's URI.
public
parseParamsFromRoute(string $route[, array<string|int, mixed> $defaultParams = array() ]) : mixed
Parameters
- $route : string
-
The route with parameter names, e.g. /user/{username}
- $defaultParams : array<string|int, mixed> = array()
-
Optional hash array of default request param values to use if they are missing from URI
Tags
Return values
mixed —setMethod()
Set the HTTP method of this request.
public
setMethod(string $method) : mixed
Parameters
- $method : string
Tags
Return values
mixed —setParams()
Set the params array.
public
setParams(mixed $params) : mixed
Parameters
- $params : mixed
Tags
Return values
mixed —getGlobalBody()
Attempts to get the raw body of the current request from super globals.
private
getGlobalBody() : string
Tags
Return values
string —getGlobalHeaders()
Tries to get the current HTTP request headers from super globals.
private
getGlobalHeaders() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —getGlobalServerValue()
Tries to get the requested param from the $_SERVER super global, otherwise returns an empty string.
private
getGlobalServerValue(string $param) : string
Parameters
- $param : string