class Request (View source)

Snapshot of the $_GET, $_POST and $_SERVER superglobals with typed accessors for controllers.

Properties

protected array $queryParams
protected array $postParams
protected array $serverParams

Methods

__construct(array|null $queryParams = null, array|null $postParams = null, array|null $serverParams = null)

Without arguments the request is a snapshot of the superglobals; given any, it is built from those arrays instead (tests, or a request assembled by hand).

void
refresh()

Refreshes the request data from the global variables

array
getQueryParams()

No description

array
getPostParams()

No description

getQueryParam(string $key, $default = null)

No description

getPostParam(string $key, $default = null)

No description

string
getQueryString(string $key, string $default = '')

Query string value as a string; $default when absent or not a string (?key[]=x).

string
getPostString(string $key, string $default = '')

POST body value as a string; $default when absent or not a string (key[]=x).

int
getPage(string $key = 'start')

1-based page number from the query string, never below 1.

int|null
getRowsPerPage(string $key = 'rows_per_page')

Requested page size from the query string, or null when absent or not a positive integer.

getParam(string $key, $default = null)

Returns a parameter from the POST body on POST requests, from the query string otherwise. For endpoints that accept both methods.

getServerParam(string $key, $default = null)

No description

string
getMethod()

No description

string
getUri()

No description

Details

__construct(array|null $queryParams = null, array|null $postParams = null, array|null $serverParams = null)

Without arguments the request is a snapshot of the superglobals; given any, it is built from those arrays instead (tests, or a request assembled by hand).

Parameters

array|null $queryParams
array|null $postParams
array|null $serverParams

void refresh()

Refreshes the request data from the global variables

Return Value

void

array getQueryParams()

No description

Return Value

array

array getPostParams()

No description

Return Value

array

getQueryParam(string $key, $default = null)

No description

Parameters

string $key
$default

getPostParam(string $key, $default = null)

No description

Parameters

string $key
$default

string getQueryString(string $key, string $default = '')

Query string value as a string; $default when absent or not a string (?key[]=x).

Parameters

string $key
string $default

Return Value

string

string getPostString(string $key, string $default = '')

POST body value as a string; $default when absent or not a string (key[]=x).

Parameters

string $key
string $default

Return Value

string

int getPage(string $key = 'start')

1-based page number from the query string, never below 1.

Parameters

string $key

Return Value

int

int|null getRowsPerPage(string $key = 'rows_per_page')

Requested page size from the query string, or null when absent or not a positive integer.

Parameters

string $key

Return Value

int|null

getParam(string $key, $default = null)

Returns a parameter from the POST body on POST requests, from the query string otherwise. For endpoints that accept both methods.

Parameters

string $key
$default

getServerParam(string $key, $default = null)

No description

Parameters

string $key
$default

string getMethod()

No description

Return Value

string

string getUri()

No description

Return Value

string