API / Minn\Runtime / Interactivity

Interactivity final class

Minn\Runtime\Interactivity · public/minn/src/Minn/Runtime/Interactivity.php · 534 lines

Server-side directive processing for the Interactivity API: the state and config stores, and the pass that resolves data-wp-bind, data-wp-class, data-wp-style, data-wp-text, and data-wp-each against state and context before the markup leaves the server. Behaviour pinned by the interactivity probe fixture.

Used by 1

Constants and properties

privateVOID = array ( 0 => 'area', 1 => 'base', 2 => 'br', 3 => 'col', 4 => 'embed', 5 => 'hr', 6 => 'img', 7 => 'input', 8 => 'link', 9 => 'meta', 10 => 'source', 11 => 'track', 12 => 'wbr', )
privateRAW = array ( 0 => 'script', 1 => 'style', 2 => 'textarea', 3 => 'title', )
privateTAG = '/<(\\/?)([a-zA-Z][^\\s\\/>]*)((?:\\s+[^\\s=\\/>]+(?:\\s*=\\s*(?:"[^"]*"|\'[^\']*\'|[^\\s"\'>]+))?)*)\\s*(\\/?)>/'
privateUNRESOLVED = '' . "\0" . 'unresolved'
privateATTR = '/\\s+([^\\s=\\/>]+)(?:\\s*=\\s*("[^"]*"|\'[^\']*\'|[^\\s"\'>]+))?/'
privatearray $state
privatearray $config
privatearray $namespaces
privatearray $contexts
private?array $element
privatebool $processing
private?Closure $routerRegion

Public

methodwhenRouterRegion(Closure $callback): void#

What to run when processing meets a router region.

methodstate(?string $namespace, array $state = array ( )): array#

Reads or extends a namespace's state.

@return array<string, mixed>
methodallState(): array#

Every namespace's state, for the client.

@return array<string, array<string, mixed>> every namespace's state, for the client
methodallConfig(): array#

Every namespace's config, for the client.

@return array<string, array<string, mixed>>
methodconfig(string $namespace, array $config = array ( )): array#

Reads or extends a namespace's config.

@return array<string, mixed>
methodcontext(?string $namespace = NULL): array#

The current directive context of a namespace.

@return array<string, mixed>
methodelement(): ?array#

The element whose directives are being evaluated.

@return array<string, mixed>|null
methodprocess(string $html): string#

HTML with its directives resolved on the server.

Internals 15

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatenamespace(): string#
privatetokenize(string $html): ?array#

Start tags, end tags, and everything between, with balance checked; null when the markup does not close what it opens.

@return list<array{kind: string, start: int, end: int, name?: string, attrs?: list<array{name: string, value: ?string, start: int, end: int}>, void?: bool, close?: int}>|null
privatewalk(array $tokens, string $html): ?string#
$tokenslist<array<string, mixed>>
privateapplyDirectives(array $token, string $tag, array $frame): string#
$tokenarray<string, mixed>
$framearray<string, mixed>
privatebind(Minn\Runtime\TagEditor $editor, string $attribute, string $path): void#
privateinteractiveNamespace(string $value): ?string#
privatepushContext(string $value): void#
privateevaluate(string $reference, string $suffix): mixed#

The value a directive path names, or UNRESOLVED when the namespace or path is empty.

privateexpandEach(array $each, array $tokens, int $closeIndex, string $html): string#
$eacharray{key: string, path: string, token: array<string, mixed>}
$tokenslist<array<string, mixed>>
privatemarkChildren(string $fragment, string $reference): string#

Every top-level start tag in the fragment gains data-wp-each-child first.

privateattributeMap(array $attrs): array#
$attrslist<array{name: string, value: ?string}>
@return array<string, mixed>
privaterelative(array $attrs, int $base): array#
$attrslist<array{name: string, value: ?string, start: int, end: int}>
@return list<array{name: string, value: ?string, start: int, end: int}>
privateescape(string $text): string#
privatecamel(string $name): string#
privatefollow(mixed $value, array $names): mixed#

A value reached through a path of keys or properties, or null from the first one that is not there.

$nameslist<string>