Request
in package
Handling Request
Tags
Table of Contents
Constants
- ACCEPTED_REQUEST_METHODS = array('get', 'post', 'put', 'patch', 'update', 'delete', 'options', 'head')
- List of accepted request methods
Properties
- $cookieData : array<string|int, mixed>
- COOKIE data of request
- $headers : array<string|int, mixed>
- Request headers
- $httpRequestMethod : string
- HTTP requested method
- $postData : array<string|int, mixed>
- POST data of request
- $url : Url
- Resolved url object
Methods
- __construct() : mixed
- Constructor to initialize the $httpRequestMethod and $url
- getClientIp() : string
- Return IP of client that made this request.
- getCookie() : string
- Returns the value of the cookie identified by $name
- getHeaders() : array<string|int, mixed>
- Returns the headers
- getHeadersFromCapturedRequest() : array<string|int, mixed>
- Returns the HTTP headers for the current real request Header keys are all caps with spaces and dashes replace by underline
- getHttpRequestMethod() : string
- Get the httpRequest method
- getParam() : string
- Returns the param identified by $name
- getParams() : array<string|int, mixed>
- Returns all params
- getUrl() : Url
- Get the resolved url object
- hasCookie() : bool
- Tells whether a cookie is set
- hasParam() : bool
- Tells whether a GET or POST parameter is set
- isCorsPreflightRequest() : bool
- Checks if the current request is a CORS-preflight request.
- isMobilePhone() : bool
- Returns true if the user agent is a mobile device (smart phone, PDA etc.)
- isTablet() : bool
- Returns true if the user agent is a tablet
- setHttpRequestMethod() : mixed
- Set the httpRequest method
- getClientIpFromHttpHeaders() : string
- Get IP address of origin client (and not of a intermediary proxy)
- sanitizeRequestMethod() : void
- Verifies that $method is a supported HTTP method.
Constants
ACCEPTED_REQUEST_METHODS
List of accepted request methods
public
array<string|int, mixed>
ACCEPTED_REQUEST_METHODS
= array('get', 'post', 'put', 'patch', 'update', 'delete', 'options', 'head')
Properties
$cookieData
COOKIE data of request
protected
array<string|int, mixed>
$cookieData
= array()
Sanitized COOKIE data
$headers
Request headers
protected
array<string|int, mixed>
$headers
= array()
Key=>value type array
$httpRequestMethod
HTTP requested method
protected
string
$httpRequestMethod
$postData
POST data of request
protected
array<string|int, mixed>
$postData
= array()
Sanitized POST data
$url
Resolved url object
protected
Url
$url
Methods
__construct()
Constructor to initialize the $httpRequestMethod and $url
public
__construct(string $method, object $resolvedUrl[, mixed $headers = array() ]) : mixed
Parameters
- $method : string
- $resolvedUrl : object
- $headers : mixed = array()
getClientIp()
Return IP of client that made this request.
public
static getClientIp([bool $trustworthyOnly = true ]) : string
If the request was routed through a proxy, then this method will return
the IP of the origin client and not the one of the proxy.
If $trustworthyOnly is set to true
, then the IP of the leftmost
trusted client is returned.
Parameters
- $trustworthyOnly : bool = true
-
See static::getClientIpOfReverseProxy()
Tags
Return values
stringgetCookie()
Returns the value of the cookie identified by $name
public
getCookie(string $name) : string
Parameters
- $name : string
-
Name of the cookie to return value of
Tags
Return values
string —Cookie value
getHeaders()
Returns the headers
public
getHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed> —Key=>value type list of headers
getHeadersFromCapturedRequest()
Returns the HTTP headers for the current real request Header keys are all caps with spaces and dashes replace by underline
public
static getHeadersFromCapturedRequest() : array<string|int, mixed>
Return values
array<string|int, mixed> —Key=>value type array
getHttpRequestMethod()
Get the httpRequest method
public
getHttpRequestMethod([bool $fromCorsPreflightRequest = false ]) : string
Parameters
- $fromCorsPreflightRequest : bool = false
-
Set to
true
to fetch the request method from a CORS-preflight request.
Return values
stringgetParam()
Returns the param identified by $name
public
getParam(string $name[, bool $get = true ]) : string
Parameters
- $name : string
-
Name of the param to return value of
- $get : bool = true
-
(optional) Set to false to check POST
Tags
Return values
string —Parameter value
getParams()
Returns all params
public
getParams([bool $get = true ]) : array<string|int, mixed>
Parameters
- $get : bool = true
-
(optional) Set to false to check POST
Return values
array<string|int, mixed> —Parameters values
getUrl()
Get the resolved url object
public
getUrl() : Url
Return values
UrlhasCookie()
Tells whether a cookie is set
public
hasCookie(string $name) : bool
Parameters
- $name : string
-
Name of the param to check
Tags
Return values
bool —True of param is set, false otherwise
hasParam()
Tells whether a GET or POST parameter is set
public
hasParam(string $name[, bool $get = true ]) : bool
Parameters
- $name : string
-
Name of the param to check
- $get : bool = true
-
(optional) Set to false to check POST
Return values
bool —True of param is set, false otherwise
isCorsPreflightRequest()
Checks if the current request is a CORS-preflight request.
public
isCorsPreflightRequest() : bool
Tags
Return values
bool —Returns true
of the current request is a CORS-preflight request.
isMobilePhone()
Returns true if the user agent is a mobile device (smart phone, PDA etc.)
public
isMobilePhone() : bool
Tags
Return values
bool —True for mobile phones, false otherwise
isTablet()
Returns true if the user agent is a tablet
public
isTablet() : bool
Tags
Return values
bool —True for tablets, false otherwise
setHttpRequestMethod()
Set the httpRequest method
public
setHttpRequestMethod(string $method) : mixed
Parameters
- $method : string
getClientIpFromHttpHeaders()
Get IP address of origin client (and not of a intermediary proxy)
protected
static getClientIpFromHttpHeaders([bool $trustworthyOnly = true ]) : string
Parameters
- $trustworthyOnly : bool = true
-
In case at least one proxy is configured (see CLX_CONFIG_TRUSTED_REVERSE_PROXY_COUNT) and $trustworthyOnly is set to
true
, then the IP of the origin client of the leftmost trusted proxy is returned. Otherwise, if set tofalse
, the leftmost IP from the HTTP header HTTP_X_FORWARDED_FOR is returned.
Tags
Return values
string —The IP address of the origin client.
sanitizeRequestMethod()
Verifies that $method is a supported HTTP method.
protected
sanitizeRequestMethod(string &$method) : void
See supported methods in static::ACCEPTED_REQUEST_METHODS. If $method is supported, it will be converted into lowercase. If $method is unsupported, then it will be set to 'none'.
Parameters
- $method : string
-
HTTP method to verify