API / Minn\Runtime / Assets

Assets final class

Minn\Runtime\Assets · public/minn/src/Minn/Runtime/Assets.php · 432 lines

The registry behind wp_register_/wp_enqueue_ for scripts and styles: handles, sources, dependencies, versions, inline additions, localized data, and the head/footer split. Printing follows the reference's tag shapes as far as captured; see contracts/runtime.md.

Uses 1

Constants and properties

privatearray $items
privatearray $queue
privatearray $done
privatearray $waiting
privatestatic ?array $defaults
private?Closure $onChange
private?Closure $beforeChange
privatereadonly string $kind

Promoted from the constructor.

Public

new__construct(string $kind)#
methodwatch(Closure $listener, ?Closure $before = NULL): void#

A listener called after every change, so a plugin-facing view can stay current; and one called before a script's data changes, so what a plugin set in that view lands first.

methodsetQueue(array $queue): void#

The queue as a plugin left it after editing the view directly.

methodregister(string $handle, string|false $src, array $deps, string|bool|null $ver, mixed $extra): bool#

Registers an asset under a handle.

methodrevise(string $handle, string|false $src, array $deps, string|bool|null $ver, mixed $extra): bool#

An existing handle's source, dependencies, version and arguments replaced, its data, inline code and place in the queue kept.

methodexternalHosts(string $ownHost): array#

The hosts the queued assets load from, other than the site's own.

@return list<string> hosts of enqueued sources (dependencies first) away from the given host, for dns-prefetch hints
methodderegister(string $handle): void#

Forgets an asset.

methodenqueue(string $handle): void#

Queues an asset for printing (probe placeholders-admin). One that is neither registered nor among the reference's own handles waits, and joins the queue when it is registered; one of the reference's own the engine ships no file for is queued as the reference would queue it.

methoddequeue(string $handle): void#

Removes an asset from the queue, or from the handles waiting for registration.

methodregistered(string $handle): bool#

Whether a handle is registered, by the site or as one the reference registers itself (data/default-assets.json).

methoddependencies(string $handle): array#

A handle's dependencies: as registered, or as the reference registers it. @return list<string>

@return list<string>
methoddependents(string $handle): array#

The registered handles that name a handle among their dependencies. @return list<string>

@return list<string>
methodreaches(array $from, string $handle): bool#

Whether a handle is a dependency, however deep, of any of the given handles.

$fromlist<string>
methodenqueued(string $handle): bool#

Queued directly, or pulled in as the dependency of something queued, however deep. The reference answers the same way, and plugin code leans on it: WooCommerce only attaches its settings blob when it finds `wc-settings` "enqueued", and nothing queues that handle by name, it only ever rides in as a dependency.

methoddoneList(): array#

The handles printed so far.

@return list<string>
methodsetDone(array $done): void#

The printed handles as a plugin left them after editing the view directly.

methoddone(string $handle): bool#

Whether a handle has been printed.

methodaddInline(string $handle, string $code, string $position): bool#

Attaches inline code to an asset.

methodaddData(string $handle, string $key, mixed $value): bool#

Attaches a data key to an asset.

methodsetTranslations(string $handle, string $domain, string $path): bool#

Names the text domain and folder a script's translations come from, and makes the script depend on wp-i18n.

methoddata(string $handle, string $key): mixed#

A data key of an asset, or false.

methodlocalize(string $handle, string $name, array $data): bool#

Attaches a localized object to a script.

methodtoPrint(): array#

Every queued handle not yet printed, dependencies first. @return list<string>

@return list<string>
methodwithPath(): array#

Enqueued handles that name a file on disk, mapped to that path. A style registered with a `path` datum is saying it can be inlined; whether it is small enough to be worth inlining is the caller's decision.

@return array<string, string> handle => path
methodunsource(string $handle): void#

Drops a handle's source so it prints as markup rather than a link.

methodmarkDone(string $handle): void#

Records a handle as printed.

methoditem(string $handle): ?array#

One registered asset, or null.

methoditems(): array#

Every registered asset.

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

The handles queued.

@return list<string>
methodkind(): string#

Whether these are scripts or styles.

Internals 5

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

privatesettle(): void#
privatechanged(): void#
privatedefaults(): array#
@return array<string, array<string, list<string>>>
privateheld(string $handle): bool#

Whether a handle is an item to attach to: one registered here, or a stylesheet the reference registers itself, held from then on with no file (the engine ships none of those) so what a plugin attaches to it still prints. A core script is not held: its inline code without the library would only fail in the browser.

privateordered(array $start): array#
$startlist<string>
@return list<string>