API / Minn\Runtime / ScriptModules

ScriptModules final class

Minn\Runtime\ScriptModules · public/minn/src/Minn/Runtime/ScriptModules.php · 393 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
privatearray $told
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
methodmarkedForEnqueue(): array#

The queued modules that are registered, in queue order, each as registered(): what the reference's get_marked_for_enqueue() answers, a module whose dependency is missing included.

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

The registered dependencies of some modules, following the given import types, each as registered() (get_dependencies()).

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

A registered module's address as the page loads it (get_src()); '' for one not registered.

methodprintImportMap(): string#

The import map script tag.

methodprintPreloads(): string#

The modulepreload links: the queued modules' static dependencies not queued themselves, each after its own (depth first, in queue order).

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 10

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#
privatetellMissing(): void#

A queued module whose dependencies are not all registered is told once, as the page first prints its module tags or preloads, not as it registers (a dependency may be registered later).

privatedependenciesFirst(array $ids): array#

The modules' registered static dependencies, each after its own: depth first, in the order the modules and their dependencies are given.

$idslist<string>
@return list<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, following only the given import types: the modules' own dependencies in declaration order, then theirs, a level at a time (probe script-modules-private).

$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#