Documentation

LocalizeResourceGroup
in package

Defines one localized resource group and generates assignment-only JavaScript resources.

Table of Contents

Properties

$exclude  : mixed
$include  : mixed
$name  : mixed
$path  : mixed
$peelCollection  : bool
Set by `extract()` when `include` peels fields from a list/map of objects.
$required  : mixed
$strategy  : mixed

Methods

__construct()  : mixed
Creates a resource group from configuration.
extract()  : mixed
Extract this group's payload from localized data and mutate `$l10n` in-place.
fromArray()  : mixed
Factory for resource group definitions.
generateJavaScript()  : mixed
Generates the JavaScript resource output for this group.
getName()  : mixed
Returns the resource group name.
getStrategy()  : mixed
Returns the loading strategy (`defer` or `lazy`).
isRequired()  : mixed
Returns whether this group is required for optimized output.
aliasSavesBytes()  : mixed
Comma-decl cost vs repeating `$accessor` once per descendant leaf.
applyIncludeExclude()  : mixed
Applies include/exclude filtering to extracted payloads.
countTrieLeaves()  : mixed
Counts assignment leaves under a trie node.
emitCompressedTrie()  : mixed
Emits alias declarations and leaf assignments from the prefix trie.
ensureIntermediatePathJs()  : string
Ensures intermediate path segments exist (all except the last).
ensurePathJs()  : string
Ensures all path segments exist (including the last).
ensurePathSegmentsJs()  : string
Emits JS statements that ensure each intermediate segment of a dotted path exists as an object. Prevents "Cannot read properties of undefined" when deferred resource scripts load in arbitrary order.
extractPeeledFields()  : array<int, array{keys: (int|string)[], value: mixed}>
Peel `include` paths from the value at `path`; keep the skeleton in `$l10n`.
generateCollectionAssignmentsScript()  : mixed
Direct assignments onto existing nodes, keyed by original index or property name.
getValueByPath()  : mixed
Reads a nested value from an array by dotted path.
includeHasWildcard()  : bool
Whether any include spec iterates a nested collection via `[]`.
insertTrie()  : mixed
Inserts one assignment path into the prefix trie.
isCollectionOfArrays()  : mixed
True when every value is an array (list or named map of objects).
jsonEncode()  : string
Encodes values as JSON in WordPress and PHPUnit environments.
nextAliasName()  : mixed
Next short local name; skips `b` (bucket) and `o` (root) because `var` hoists.
normalizeWildcardPath()  : mixed
`others.items[].purpose` → path `others.items` + include `purpose`.
parseIncludeSpec()  : array<string|int, string>
Tokenize `technicalDefinitions[].purpose` into property / iterate steps.
peelBySpec()  : mixed
Walk one include spec, record leaf assignments, unset extracted values in-place.
setValueByPath()  : mixed
Writes a nested value into an array by dotted path.
shouldPeel()  : mixed
`include` peels nested fields; collection at `path` iterates each child first.
toJsAccessor()  : mixed
Converts a dotted path to a JavaScript object accessor.
trieChildKeysAreNumeric()  : mixed
Whether the child keys of the trie node are numeric.
unsetValueByPath()  : mixed
Unsets a nested value in an array by dotted path.

Properties

$peelCollection

Set by `extract()` when `include` peels fields from a list/map of objects.

private bool $peelCollection = false

Methods

__construct()

Creates a resource group from configuration.

public __construct(string $name[, array<string|int, mixed> $definition = [] ]) : mixed
Parameters
$name : string
$definition : array<string|int, mixed> = []

extract()

Extract this group's payload from localized data and mutate `$l10n` in-place.

public extract(array<string|int, mixed> &$l10n) : mixed
Parameters
$l10n : array<string|int, mixed>

fromArray()

Factory for resource group definitions.

public static fromArray(string $name[, array<string|int, mixed> $definition = [] ]) : mixed
Parameters
$name : string
$definition : array<string|int, mixed> = []

generateJavaScript()

Generates the JavaScript resource output for this group.

public generateJavaScript(string $bucketId, mixed $payload) : mixed
Parameters
$bucketId : string
$payload : mixed

getStrategy()

Returns the loading strategy (`defer` or `lazy`).

public getStrategy() : mixed

isRequired()

Returns whether this group is required for optimized output.

public isRequired() : mixed

aliasSavesBytes()

Comma-decl cost vs repeating `$accessor` once per descendant leaf.

private aliasSavesBytes(string $accessor, int $uses) : mixed
Parameters
$accessor : string
$uses : int

applyIncludeExclude()

Applies include/exclude filtering to extracted payloads.

private applyIncludeExclude(mixed $value) : mixed
Parameters
$value : mixed

countTrieLeaves()

Counts assignment leaves under a trie node.

private countTrieLeaves(array<string|int, mixed> $node) : mixed
Parameters
$node : array<string|int, mixed>

emitCompressedTrie()

Emits alias declarations and leaf assignments from the prefix trie.

private emitCompressedTrie(array<string|int, mixed> $node, string $accessor, array<string|int, string> &$decls, string &$stmts, int &$aliasIndex) : mixed
Parameters
$node : array<string|int, mixed>
$accessor : string
$decls : array<string|int, string>
$stmts : string
$aliasIndex : int

ensureIntermediatePathJs()

Ensures intermediate path segments exist (all except the last).

private ensureIntermediatePathJs(string $base, string $path) : string
Parameters
$base : string
$path : string
Return values
string

ensurePathJs()

Ensures all path segments exist (including the last).

private ensurePathJs(string $base, string $path) : string
Parameters
$base : string
$path : string
Return values
string

ensurePathSegmentsJs()

Emits JS statements that ensure each intermediate segment of a dotted path exists as an object. Prevents "Cannot read properties of undefined" when deferred resource scripts load in arbitrary order.

private ensurePathSegmentsJs(string $base, string $path, bool $includeLastSegment) : string
Parameters
$base : string

JS expression for the root (e.g. o)

$path : string

Dotted path (e.g. others.frontend)

$includeLastSegment : bool

When true, ensures the entire path including the leaf.

Return values
string —

JS statements like o["others"]=o["others"]||};

extractPeeledFields()

Peel `include` paths from the value at `path`; keep the skeleton in `$l10n`.

private extractPeeledFields(array<string|int, mixed> &$l10n, array<string|int, mixed> $value) : array<int, array{keys: (int|string)[], value: mixed}>
Parameters
$l10n : array<string|int, mixed>
$value : array<string|int, mixed>
Return values
array<int, array{keys: (int|string)[], value: mixed}>

generateCollectionAssignmentsScript()

Direct assignments onto existing nodes, keyed by original index or property name.

private generateCollectionAssignmentsScript(string $bucketId, array<int, array{keys: (int|string)[], value: mixed}> $payload) : mixed

Shared prefixes become short locals when that shrinks the file.

Parameters
$bucketId : string
$payload : array<int, array{keys: (int|string)[], value: mixed}>

getValueByPath()

Reads a nested value from an array by dotted path.

private getValueByPath(array<string|int, mixed> $array, string $path) : mixed
Parameters
$array : array<string|int, mixed>
$path : string

includeHasWildcard()

Whether any include spec iterates a nested collection via `[]`.

private includeHasWildcard() : bool
Return values
bool

insertTrie()

Inserts one assignment path into the prefix trie.

private insertTrie(array<string|int, mixed> &$trie, array<string|int, int|string> $keys, mixed $value) : mixed
Parameters
$trie : array<string|int, mixed>
$keys : array<string|int, int|string>
$value : mixed

isCollectionOfArrays()

True when every value is an array (list or named map of objects).

private isCollectionOfArrays(mixed $value) : mixed
Parameters
$value : mixed

jsonEncode()

Encodes values as JSON in WordPress and PHPUnit environments.

private jsonEncode(mixed $value) : string
Parameters
$value : mixed
Return values
string

nextAliasName()

Next short local name; skips `b` (bucket) and `o` (root) because `var` hoists.

private nextAliasName(int &$index) : mixed
Parameters
$index : int

normalizeWildcardPath()

`others.items[].purpose` → path `others.items` + include `purpose`.

private normalizeWildcardPath() : mixed

parseIncludeSpec()

Tokenize `technicalDefinitions[].purpose` into property / iterate steps.

private parseIncludeSpec(string $spec) : array<string|int, string>
Parameters
$spec : string
Return values
array<string|int, string>

peelBySpec()

Walk one include spec, record leaf assignments, unset extracted values in-place.

private peelBySpec(mixed &$node, array<string|int, string> $steps, array<string|int, int|string> $prefix, array<int, array{keys: (int|string)[], value: mixed}> &$payload) : mixed
Parameters
$node : mixed
$steps : array<string|int, string>
$prefix : array<string|int, int|string>
$payload : array<int, array{keys: (int|string)[], value: mixed}>

setValueByPath()

Writes a nested value into an array by dotted path.

private setValueByPath(array<string|int, mixed> &$array, string $path, mixed $value) : mixed
Parameters
$array : array<string|int, mixed>
$path : string
$value : mixed

shouldPeel()

`include` peels nested fields; collection at `path` iterates each child first.

private shouldPeel(mixed $value) : mixed
Parameters
$value : mixed

toJsAccessor()

Converts a dotted path to a JavaScript object accessor.

private toJsAccessor(string $base, string $path) : mixed
Parameters
$base : string
$path : string

trieChildKeysAreNumeric()

Whether the child keys of the trie node are numeric.

private trieChildKeysAreNumeric(array<string|int, mixed> $trieNode) : mixed
Parameters
$trieNode : array<string|int, mixed>

unsetValueByPath()

Unsets a nested value in an array by dotted path.

private unsetValueByPath(array<string|int, mixed> &$array, string $path) : mixed
Parameters
$array : array<string|int, mixed>
$path : string
On this page

Search results