class CRM_Utils_Request

Class for managing a http request

Methods

static string
id()

Get a unique ID for the request.

static mixed
retrieve(string $name, string $type, object $store = NULL, bool $abort = FALSE, mixed $default = NULL, string $method = 'REQUEST', bool $isThrowException = FALSE)

Retrieve a value from the request (GET/POST/REQUEST)

static mixed
getValue(string $name, array $method)

No description

static array
exportValues() deprecated

No description

static mixed
retrieveValue(string $name, string $type, mixed $defaultValue = NULL, bool $isRequired = FALSE, string $method = 'REQUEST')

Retrieve a variable from the http request.

static string
retrieveComponent(array $attributes)

Retrieve the component from the action attribute of a form.

Details

at line 60
static string id()

Get a unique ID for the request.

This unique ID is assigned to mysql when the connection is opened and is available in PHP.

The intent is that it is available for logging purposes and for triggers.

The resulting string is 17 characters long. This consists of 13 characters of uniqid and 4 more random characters.

Uniqid is unique to the microsecond - to make it more unique we add 4 more characters but stop short of the full 23 character string that a prefix would generate.

It is intended that this string will be saved to log tables so striking a balance between uniqueness and length is important. Note that I did check & lining up with byte values (e.g 16 characters) does not confer any benefits. Using a CHAR field rather than VARCHAR may improve speed, if indexed.

Return Value

string

at line 90
static mixed retrieve(string $name, string $type, object $store = NULL, bool $abort = FALSE, mixed $default = NULL, string $method = 'REQUEST', bool $isThrowException = FALSE)

Retrieve a value from the request (GET/POST/REQUEST)

Parameters

string $name Name of the variable to be retrieved.
string $type Type of the variable (see CRM_Utils_Type for details).
object $store Session scope where variable is stored.
bool $abort TRUE, if the variable is required.
mixed $default Default value of the variable if not present.
string $method Where to look for the variable - 'GET', 'POST' or 'REQUEST'.
bool $isThrowException Should a an exception be thrown rather than a fatal.

Return Value

mixed The value of the variable

Exceptions

CRM_Core_Exception

at line 151
static protected mixed getValue(string $name, array $method)

Parameters

string $name Name of the variable to be retrieved.
array $method
  • '$_GET', '$_POST' or '$_REQUEST'.

Return Value

mixed The value of the variable

at line 180
static array exportValues() deprecated

deprecated We should use a function that checks url values. This is a replacement for $_REQUEST which includes $_GET/$_POST but excludes $_COOKIE / $_ENV / $_SERVER.

Return Value

array

at line 220
static mixed retrieveValue(string $name, string $type, mixed $defaultValue = NULL, bool $isRequired = FALSE, string $method = 'REQUEST')

Retrieve a variable from the http request.

Parameters

string $name Name of the variable to be retrieved.
string $type Type of the variable (see CRM_Utils_Type for details). Most common options are: - 'Integer' - 'Positive' - 'CommaSeparatedIntegers' - 'Boolean' - 'String'
mixed $defaultValue Default value of the variable if not present.
bool $isRequired Is the variable required for this function to proceed without an exception.
string $method Where to look for the value - GET|POST|REQUEST

Return Value

mixed

Exceptions

CRM_Core_Exception

at line 242
static string retrieveComponent(array $attributes)

Retrieve the component from the action attribute of a form.

Contribution Page forms and Event Management forms detect the value of a component (and therefore the desired tab key) by reaching into the "action" attribute of a form and reading the final item of the path. In WordPress, however, the URL may be urlencoded, and so the URL may need to be decoded before parsing it.

Parameters

array $attributes The form attributes array.

Return Value

string The desired value.

See also

https://lab.civicrm.org/dev/wordpress/issues/12#note_10699