Documentation

Request
in package

This class has the methods to easily access request data.

This class uses the 'thephpleague' URLSearchParams component, so it is tightly coupled to that dependency.

Tags
see
https://uri.thephpleague.com/components/7.0/urlsearchparams/

Table of Contents

Properties

$cookies  : stdClass
Holds the cookies
$isHTTP  : bool
Holds true if the request is an HTTP request
$isXHR  : bool
Holds true if the request is an XHR request
$method  : string
The method used for the request
$payload  : stdClass
Holds the request data received
$shouldBeIgnored  : bool
Holds the bool var according to config->request_ignore if resource is in a path that should be ignored
$uri  : stdClass
Holds the uri data.
$uriParams  : array<string|int, mixed>
Holds the query string parameters as an associative array with public visibility
$params  : URLSearchParams
Holds the query string parameters in an URLSearchParams object
$remoteAddress  : string
Holds the detected IP address from the client that is requesting a resource

Methods

__construct()  : mixed
fillPayload()  : mixed
Fills payload property with array
getAllUriParamWithName()  : mixed
Wrapper function of League\Uri\Components\URLSearchParams::getAll().
getFomPayload()  : mixed
Returns the value of a var from the payload property.
getRemoteAddress()  : string
Gets the value of the remote address property
getRequestMethod()  : string
Returns the request method (GET, POST, PUT, DELETE)
getUriParam()  : mixed
Wrapper function of League\Uri\Components\URLSearchParams::get().
hasUpload()  : bool
Determines if request has uploaded files
identifyAllUriParams()  : void
Identifies all URI params in the query string and fills the $uriParams property
identifyParamsInUri()  : void
Identifies the query string parameters and stores them in the local var $params
init()  : void
Initialize values or properties in the singleton instance
payloadAsArray()  : array<string|int, mixed>
Returns the payload as an associative array
payloadToArray()  : array<string|int, mixed>
Gets the data in the payload and returns it as an array, keeps the payload intact
processUri()  : void
Process the URL query string
removeParamFromUri()  : void
Wrapper function of League\Uri\Components\URLSearchParams::delete().
setPayload()  : void
Loads all body data parameters from an array given or from the request body
setToPayload()  : void
Set a value in the payload property.
sortUriParams()  : void
Wrapper function of League\Uri\Components\URLSearchParams::sort().
toArray()  : array<string|int, mixed>
Takes an array or stdClass object and casts it to array
toObject()  : object
Takes an array or stdClass object and casts it to object
uriHasParam()  : bool
Wrapper function of League\Uri\Components\URLSearchParams::has().
castToDetectedType()  : mixed
Casts the value to the identified type (int, double, bool, string)
setRemoteAddress()  : void
Sets the remote address from the client in a property of this class.
setRequestMethod()  : void
setShouldBeIgnored()  : void
Determines if the request is trying to get a resource in a path that should be ignored and not routed to a controller, like assets

Properties

$cookies

Holds the cookies

public stdClass $cookies

$isHTTP

Holds true if the request is an HTTP request

public bool $isHTTP = false

$isXHR

Holds true if the request is an XHR request

public bool $isXHR = false

$method

The method used for the request

public string $method

$payload

Holds the request data received

public stdClass $payload

$shouldBeIgnored

Holds the bool var according to config->request_ignore if resource is in a path that should be ignored

public bool $shouldBeIgnored = false

$uri

Holds the uri data.

public stdClass $uri

$uriParams

Holds the query string parameters as an associative array with public visibility

public array<string|int, mixed> $uriParams

$params

Holds the query string parameters in an URLSearchParams object

private URLSearchParams $params

$remoteAddress

Holds the detected IP address from the client that is requesting a resource

private string $remoteAddress

Methods

__construct()

public __construct() : mixed

fillPayload()

Fills payload property with array

public fillPayload(array<string|int, mixed>|stdClass $payload_data) : mixed
Parameters
$payload_data : array<string|int, mixed>|stdClass

getAllUriParamWithName()

Wrapper function of League\Uri\Components\URLSearchParams::getAll().

public getAllUriParamWithName(string $paramName) : mixed

Returns an array of values if the query string contains one or more parameters with the same name but different value

Parameters
$paramName : string

getFomPayload()

Returns the value of a var from the payload property.

public getFomPayload(string $var) : mixed
Parameters
$var : string

getRemoteAddress()

Gets the value of the remote address property

public getRemoteAddress() : string
Return values
string

getRequestMethod()

Returns the request method (GET, POST, PUT, DELETE)

public getRequestMethod() : string
Return values
string

getUriParam()

Wrapper function of League\Uri\Components\URLSearchParams::get().

public getUriParam(string $paramName) : mixed

Returns the value of the identified query string parameter

Parameters
$paramName : string
  • the name of the parameter

hasUpload()

Determines if request has uploaded files

public hasUpload() : bool
Return values
bool

identifyAllUriParams()

Identifies all URI params in the query string and fills the $uriParams property

public identifyAllUriParams() : void

identifyParamsInUri()

Identifies the query string parameters and stores them in the local var $params

public identifyParamsInUri(string $query) : void
Parameters
$query : string

init()

Initialize values or properties in the singleton instance

public init() : void

payloadAsArray()

Returns the payload as an associative array

public payloadAsArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

payloadToArray()

Gets the data in the payload and returns it as an array, keeps the payload intact

public payloadToArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

processUri()

Process the URL query string

public processUri() : void

removeParamFromUri()

Wrapper function of League\Uri\Components\URLSearchParams::delete().

public removeParamFromUri(string $paramName) : void

Removes the params from the uri that matches the $paramName

Parameters
$paramName : string

setPayload()

Loads all body data parameters from an array given or from the request body

public setPayload([mixed $body = null ]) : void
Parameters
$body : mixed = null

setToPayload()

Set a value in the payload property.

public setToPayload(string $var, mixed $value) : void
Parameters
$var : string
$value : mixed

sortUriParams()

Wrapper function of League\Uri\Components\URLSearchParams::sort().

public sortUriParams() : void

Sorts the params identified from the URL

toArray()

Takes an array or stdClass object and casts it to array

public toArray(array<string|int, mixed>|stdClass $var) : array<string|int, mixed>
Parameters
$var : array<string|int, mixed>|stdClass
Return values
array<string|int, mixed>

toObject()

Takes an array or stdClass object and casts it to object

public toObject(array<string|int, mixed>|stdClass $var) : object
Parameters
$var : array<string|int, mixed>|stdClass
Return values
object

uriHasParam()

Wrapper function of League\Uri\Components\URLSearchParams::has().

public uriHasParam(string $paramName) : bool

Returns true if param exists in the query string, false if not.

Parameters
$paramName : string
Return values
bool

castToDetectedType()

Casts the value to the identified type (int, double, bool, string)

private castToDetectedType(mixed $value) : mixed
Parameters
$value : mixed

setRequestMethod()

private setRequestMethod() : void

setShouldBeIgnored()

Determines if the request is trying to get a resource in a path that should be ignored and not routed to a controller, like assets

private setShouldBeIgnored() : void

        
On this page

Search results