CoolCMS API

ApiClientFormPayload
in package

FinalYes

Maps the external Api client form values to the payload for `api/system/api-client` `create` / `update`.

IMPORTANT: update replaces the name, the notes and all four limits, so an omitted limit falls back to the default. The payload therefore always carries all four (an empty field is null, meaning default) and always roleIds; omitting roleIds would leave the roles unchanged on edit.

Required roles (guest) are checked and disabled in the form; the browser does not submit a disabled checkbox and Nette drops it from the value, so callers pass them separately as $requiredRoleIds. The Api adds them anyway (ApiClientManager::withRequiredRoles()).

Only on creation ($withFirstKey) the payload also carries the first key: keyLabel and keyExpiresAt (a datetime-local input value, empty means no expiry). Editing an application does not touch keys (they have their own page), so update does not carry them.

Static methods only, no service: the private constructor keeps it out of DI search.

Table of Contents

Constants

KEY_LABEL_MAX_LENGTH  : int = 100
Longest key label; matches `ApiClientManager::KEY_LABEL_MAX_LENGTH` (Api).
LIMIT_FIELDS  : array<string|int, mixed> = ['limitPerSecond', 'limitPerMinute', 'userLimit...
Order and names match `App\UI\Api\System\Models\Managers\ApiClientManager::LIMIT_FIELDS`.
LIMIT_MAX  : int = 1000000
Upper bound of a limit; matches `App\UI\Api\System\Models\Managers\ApiClientManager::LIMIT_MAX`.
MAX_VALID_KEYS  : int = 5
Ceiling of valid keys per application; matches `ApiClientManager::MAX_VALID_KEYS` (Api).

Methods

build()  : array{name: string, notes: string|null, limitPerSecond: int|null, limitPerMinute: int|null, userLimitPerMinute: int|null, ipLimitPerMinute: int|null, roleIds: list, keyLabel?: string|null, keyExpiresAt?: string|null}
buildKey()  : array{keyLabel: string|null, keyExpiresAt: string|null}
Maps the key form values (label, expiry) to the `issueKey` / `updateKey` arguments.
__construct()  : mixed
limit()  : int|null
Returns the integer limit; empty or non-numeric becomes `null` (default). The form and the Api validate the range.
roleIds()  : array<int, int>
text()  : string|null
Returns the trimmed text; empty becomes `null`.

Constants

KEY_LABEL_MAX_LENGTH

Longest key label; matches `ApiClientManager::KEY_LABEL_MAX_LENGTH` (Api).

public int KEY_LABEL_MAX_LENGTH = 100

LIMIT_FIELDS

Order and names match `App\UI\Api\System\Models\Managers\ApiClientManager::LIMIT_FIELDS`.

public array<string|int, mixed> LIMIT_FIELDS = ['limitPerSecond', 'limitPerMinute', 'userLimitPerMinute', 'ipLimitPerMinute']

LIMIT_MAX

Upper bound of a limit; matches `App\UI\Api\System\Models\Managers\ApiClientManager::LIMIT_MAX`.

public int LIMIT_MAX = 1000000

MAX_VALID_KEYS

Ceiling of valid keys per application; matches `ApiClientManager::MAX_VALID_KEYS` (Api).

public int MAX_VALID_KEYS = 5

Methods

build()

public static build(iterable<string, mixed> $values[, array<int, int> $requiredRoleIds = [] ][, bool $withFirstKey = false ]) : array{name: string, notes: string|null, limitPerSecond: int|null, limitPerMinute: int|null, userLimitPerMinute: int|null, ipLimitPerMinute: int|null, roleIds: list, keyLabel?: string|null, keyExpiresAt?: string|null}
Parameters
$values : iterable<string, mixed>

form values (name, notes, limits, roleIds, on creation keyLabel, keyExpiresAt)

$requiredRoleIds : array<int, int> = []

roles the client always has (guest)

$withFirstKey : bool = false

creation: add the first key fields

Return values
array{name: string, notes: string|null, limitPerSecond: int|null, limitPerMinute: int|null, userLimitPerMinute: int|null, ipLimitPerMinute: int|null, roleIds: list, keyLabel?: string|null, keyExpiresAt?: string|null}

buildKey()

Maps the key form values (label, expiry) to the `issueKey` / `updateKey` arguments.

public static buildKey(iterable<string, mixed> $values) : array{keyLabel: string|null, keyExpiresAt: string|null}
Parameters
$values : iterable<string, mixed>

keyLabel, keyExpiresAt

Return values
array{keyLabel: string|null, keyExpiresAt: string|null}

limit()

Returns the integer limit; empty or non-numeric becomes `null` (default). The form and the Api validate the range.

private static limit(mixed $value) : int|null
Parameters
$value : mixed
Return values
int|null

roleIds()

private static roleIds(mixed $value) : array<int, int>
Parameters
$value : mixed
Return values
array<int, int>

text()

Returns the trimmed text; empty becomes `null`.

private static text(mixed $value) : string|null
Parameters
$value : mixed
Return values
string|null
On this page

Search results