CRM_Utils_Request
in package
Class for managing a http request
Table of Contents
Methods
- exportValues() : array<string|int, mixed>
- id() : string
- Get a unique ID for the request.
- retrieve() : mixed
- Retrieve a value from the request (GET/POST/REQUEST)
- retrieveComponent() : string
- Retrieve the component from the action attribute of a form.
- retrieveValue() : mixed
- Retrieve a variable from the http request.
- getValue() : mixed
Methods
exportValues()
public
static exportValues() : array<string|int, mixed>
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 values
array<string|int, mixed>id()
Get a unique ID for the request.
public
static id() : string
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 values
stringretrieve()
Retrieve a value from the request (GET/POST/REQUEST)
public
static retrieve(string $name, string $type[, object $store = NULL ][, bool $abort = FALSE ][, mixed $default = NULL ][, string $method = 'REQUEST' ]) : mixed
Parameters
- $name : string
-
Name of the variable to be retrieved.
- $type : string
-
Type of the variable (see CRM_Utils_Type for details).
- $store : object = NULL
-
Session scope where variable is stored.
- $abort : bool = FALSE
-
TRUE, if the variable is required.
- $default : mixed = NULL
-
Default value of the variable if not present.
- $method : string = 'REQUEST'
-
Where to look for the variable - 'GET', 'POST' or 'REQUEST'.
Tags
Return values
mixed —The value of the variable
retrieveComponent()
Retrieve the component from the action attribute of a form.
public
static retrieveComponent(array<string|int, mixed> $attributes) : string
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
- $attributes : array<string|int, mixed>
-
The form attributes array.
Tags
Return values
string —The desired value.
retrieveValue()
Retrieve a variable from the http request.
public
static retrieveValue(string $name, string $type[, mixed $defaultValue = NULL ][, bool $isRequired = FALSE ][, string $method = 'REQUEST' ]) : mixed
Parameters
- $name : string
-
Name of the variable to be retrieved.
- $type : string
-
Type of the variable (see CRM_Utils_Type for details). Most common options are:
- 'Integer'
- 'Positive'
- 'CommaSeparatedIntegers'
- 'Boolean'
- 'String'
- $defaultValue : mixed = NULL
-
Default value of the variable if not present.
- $isRequired : bool = FALSE
-
Is the variable required for this function to proceed without an exception.
- $method : string = 'REQUEST'
-
Where to look for the value - GET|POST|REQUEST
Tags
getValue()
protected
static getValue(string $name, array<string|int, mixed> $method) : mixed
Parameters
- $name : string
-
Name of the variable to be retrieved.
- $method : array<string|int, mixed>
-
- '$_GET', '$_POST' or '$_REQUEST'.
Return values
mixed —The value of the variable