CoolCMS API

RequestParamShape
in package

FinalYes

Strict shape parser for parameters of external Api actions (`action*()` reading `getRequestParameters()`).

Query and form parameters arrive as strings or arrays, and plain PHP casts silently change their meaning: (int) ['999'] is 1, (bool) 'false' is true, (int) '1e2' is 100, and a scalar passed into an array typed helper is a TypeError (HTTP 500). Every method returns null for a value of the wrong shape, so the caller can reject the request instead of acting on a different value. Internal bridge calls pass native types straight to internalAction*() and never come through here.

Table of Contents

Constants

EXTERNAL_LIST_DEFAULT_LIMIT  : int = 50
Default page size of the external `get-all` when the caller sends no `limit`.
EXTERNAL_LIST_MAX_LIMIT  : int = 500
Hard cap of `limit` on the external path; a larger value is clamped, not rejected.
FALSE_VALUES  : array<string|int, mixed> = ['0', 'false', 'off']
TRUE_VALUES  : array<string|int, mixed> = ['1', 'true', 'on']

Methods

arrayOrNull()  : array<string|int, mixed>|null
The array itself, or `null` for any non-array value (missing parameter included).
bool()  : bool|null
Native bool, `1` / `0`, or one of the strings `1|0|true|false|on|off` (case-insensitive); anything else — `'yes'`, `''`, `null`, an array — is `null`.
externalListLimit()  : int
Returns the collection `limit` of an external request.
isArrayOrAbsent()  : bool
Optional array parameter: absent (`null`) or a real array. A scalar is the wrong shape.
nonNegativeInt()  : int|null
Same contract as {@see self::positiveInt()}, but `0` / `'0'` is accepted — for parameters where zero is a documented sentinel (tree root, "first position").
positiveInt()  : int|null
Native int > 0 or a string of digits only (no sign, decimals, exponent, whitespace, array, overflow).
positiveIntList()  : array<int, int>|null
Non-empty array whose every item is a {@see self::positiveInt()}; anything else (scalar, empty array, one invalid item) is `null`.
stringOrList()  : string|array<int, string>|null
Non-empty string, or an array whose every item is a non-empty string (re-indexed to a list; an empty array is allowed). Anything else — bool, number, `''`, a nested array — is `null`. Used for `includes` (`'*'`, one dot path, or a list of dot paths).

Constants

EXTERNAL_LIST_DEFAULT_LIMIT

Default page size of the external `get-all` when the caller sends no `limit`.

public int EXTERNAL_LIST_DEFAULT_LIMIT = 50

EXTERNAL_LIST_MAX_LIMIT

Hard cap of `limit` on the external path; a larger value is clamped, not rejected.

public int EXTERNAL_LIST_MAX_LIMIT = 500

FALSE_VALUES

private array<string|int, mixed> FALSE_VALUES = ['0', 'false', 'off']

TRUE_VALUES

private array<string|int, mixed> TRUE_VALUES = ['1', 'true', 'on']

Methods

arrayOrNull()

The array itself, or `null` for any non-array value (missing parameter included).

public static arrayOrNull(mixed $value) : array<string|int, mixed>|null
Parameters
$value : mixed
Return values
array<string|int, mixed>|null

bool()

Native bool, `1` / `0`, or one of the strings `1|0|true|false|on|off` (case-insensitive); anything else — `'yes'`, `''`, `null`, an array — is `null`.

public static bool(mixed $value) : bool|null
Parameters
$value : mixed
Return values
bool|null

externalListLimit()

Returns the collection `limit` of an external request.

public static externalListLimit(mixed $value) : int

A missing, non-numeric or non-positive value gives self::EXTERNAL_LIST_DEFAULT_LIMIT; a value above self::EXTERNAL_LIST_MAX_LIMIT is clamped. Internal calls (ApiBridge, internalActionGetAll(), exports) do not come through here and stay uncapped.

Parameters
$value : mixed
Return values
int

isArrayOrAbsent()

Optional array parameter: absent (`null`) or a real array. A scalar is the wrong shape.

public static isArrayOrAbsent(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

nonNegativeInt()

Same contract as {@see self::positiveInt()}, but `0` / `'0'` is accepted — for parameters where zero is a documented sentinel (tree root, "first position").

public static nonNegativeInt(mixed $value) : int|null
Parameters
$value : mixed
Return values
int|null

positiveInt()

Native int > 0 or a string of digits only (no sign, decimals, exponent, whitespace, array, overflow).

public static positiveInt(mixed $value) : int|null
Parameters
$value : mixed
Return values
int|null

positiveIntList()

Non-empty array whose every item is a {@see self::positiveInt()}; anything else (scalar, empty array, one invalid item) is `null`.

public static positiveIntList(mixed $value) : array<int, int>|null
Parameters
$value : mixed
Return values
array<int, int>|null

stringOrList()

Non-empty string, or an array whose every item is a non-empty string (re-indexed to a list; an empty array is allowed). Anything else — bool, number, `''`, a nested array — is `null`. Used for `includes` (`'*'`, one dot path, or a list of dot paths).

public static stringOrList(mixed $value) : string|array<int, string>|null
Parameters
$value : mixed
Return values
string|array<int, string>|null
On this page

Search results