API / Minn\Runtime / ScriptModules

ScriptModules final class

Minn\Runtime\ScriptModules · public/minn/src/Minn/Runtime/ScriptModules.php · 303 lines

The script modules registry: registrations with typed dependencies, the queue, and the four things a page prints from it (the import map, module preloads, the module tags split head/footer, and per-module JSON data). Behaviour pinned by the script-modules probe fixture.

Used by 1

Constants and properties

privatePRIORITIES = array ( 0 => 'high', 1 => 'low', 2 => 'auto', )
privatearray $registered
privatearray $queue
privatearray $done
privatebool $a11yAvailable
privatebool $a11yPrinted
privatereadonly Closure $url

Promoted from the constructor.

privatereadonly Closure $data

Promoted from the constructor.

Public

new__construct(Closure $url, Closure $data)#
$urlClosure(string, string|false|null): stringturns a src and version into the printed URL
$dataClosure(string, array<string, mixed>): array<string, mixed>applies the module data filter
methodregister(string $id, string $src, array $deps, string|false|null $version, array $args): void#

Registers a module by id.

$depslist<string|array{id: string, import?: string}>
methodenqueue(string $id, string $src, array $deps, string|false|null $version, array $args): void#

Queues a module, registering it when a source is given.

methoddequeue(string $id): void#

Removes a module from the queue.

methodderegister(string $id): void#

Forgets a module.

methodsetFetchpriority(string $id, string $priority): bool#

Sets a module's fetch priority.

methodmoveToFooter(string $id): bool#

Moves a module to the footer or the head.

methodmoveToHead(string $id): bool#

Prints a module in the head; false when it is not registered.

methodqueue(): array#

The module ids queued.

@return list<string>
methodregistered(string $id): ?array#

One registered module, or null.

@return array{src: string, version: string|false|null, dependencies: list<array{id: string, import: string}>, in_footer: bool, fetchpriority: string}|null
methodprintImportMap(): string#

The import map script tag.

methodprintPreloads(): string#

The modulepreload links.

methodprintHead(): string#

The head's module tags.

methodprintFooter(): string#

The footer's module tags.

methodprintData(): string#

The script-module-data tags.

methodprintA11y(): string#

The a11y module's tag, once.

Internals 8

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

privateplaceIn(string $id, string $where): bool#
privateprintTags(bool $footer): string#
privatemarked(): array#

Queued modules that are registered with every dependency registered, in queue order.

privatecomplete(string $id, array $seen): bool#
$seenlist<string>
privatedependencies(array $ids, array $types): array#

Every registered dependency of the given modules, depth first in declaration order, following only the given import types.

$idslist<string>
$typeslist<string>
@return list<string>
privateurlOf(string $id): string#

A module's address with its version, as plugins may change it (script_module_loader_src).

privateattr(string $value): string#
privatewrong(string $function, string $message, string $version): void#