CoolCMS API

CustomAssetPayload
in package

FinalYes

Normalization and validation of the custom code payload (code library).

IMPORTANT: one source of rules for both sides of the bridge. The Api operation (CustomAssetLibraryTrait::saveCustomAsset()) is the authority and normalizes the payload before touching the transaction. The admin calls the same normalizer as a preflight check (code form and page tab) to catch bad data before sending. If each side wrote its own check, they would drift apart.

A normalized row is a plain array, not an entity: the payload travels over the http bridge and an entity would have to be hydrated on both sides.

Tags
phpstan-type

NormalizedAsset array{id: int|null, name: string, type: string, placement: string, cookieCategory: string, code: string, active: bool, sort: int, addToNewPages: bool}

Table of Contents

Methods

normalizeAsset()  : Result
Validates and normalizes one code row (`save-asset`).
normalizeIds()  : Result
Validates and normalizes a set of ids (`sync-page`): duplicates merge silently and the order is kept (the first occurrence decides the position).
flag()  : bool|null
Missing / `null` = false; otherwise {@see RequestParamShape::bool()}, `null` = invalid.
str()  : string

Methods

normalizeAsset()

Validates and normalizes one code row (`save-asset`).

public static normalizeAsset(array<int|string, mixed> $row) : Result
Parameters
$row : array<int|string, mixed>
Return values
Result —

data = NormalizedAsset on success

normalizeIds()

Validates and normalizes a set of ids (`sync-page`): duplicates merge silently and the order is kept (the first occurrence decides the position).

public static normalizeIds(array<int|string, mixed> $ids) : Result
Parameters
$ids : array<int|string, mixed>
Return values
Result —

data = list<int> on success

flag()

Missing / `null` = false; otherwise {@see RequestParamShape::bool()}, `null` = invalid.

private static flag(array<int|string, mixed> $row, string $key) : bool|null
Parameters
$row : array<int|string, mixed>
$key : string
Return values
bool|null

str()

private static str(mixed $value) : string
Parameters
$value : mixed
Return values
string
On this page

Search results