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.
Constants and properties
| private | array $items | |
| private | array $queue | |
| private | array $done | |
| private | array $waiting | |
| private | static ?array $defaults | |
| private | ?Closure $onChange | |
| private | ?Closure $beforeChange | |
| private | readonly string $kind | Promoted from the constructor. |
Public
| new | __construct(string $kind)# | ||||
| method | watch(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. | |||
| method | setQueue(array $queue): void# | The queue as a plugin left it after editing the view directly. | |||
| method | register(string $handle, string|false $src, array $deps, string|bool|null $ver, mixed $extra): bool# | Registers an asset under a handle. | |||
| method | revise(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. | |||
| method | externalHosts(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 | |||
| method | deregister(string $handle): void# | Forgets an asset. | |||
| method | enqueue(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. | |||
| method | dequeue(string $handle): void# | Removes an asset from the queue, or from the handles waiting for registration. | |||
| method | registered(string $handle): bool# | Whether a handle is registered, by the site or as one the reference registers itself (data/default-assets.json). | |||
| method | dependencies(string $handle): array# | A handle's dependencies: as registered, or as the reference registers it. @return list<string> @return list<string> | |||
| method | dependents(string $handle): array# | The registered handles that name a handle among their dependencies. @return list<string> @return list<string> | |||
| method | reaches(array $from, string $handle): bool# | Whether a handle is a dependency, however deep, of any of the given handles.
| |||
| method | enqueued(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. | |||
| method | doneList(): array# | The handles printed so far. @return list<string> | |||
| method | setDone(array $done): void# | The printed handles as a plugin left them after editing the view directly. | |||
| method | done(string $handle): bool# | Whether a handle has been printed. | |||
| method | addInline(string $handle, string $code, string $position): bool# | Attaches inline code to an asset. | |||
| method | addData(string $handle, string $key, mixed $value): bool# | Attaches a data key to an asset. | |||
| method | setTranslations(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. | |||
| method | data(string $handle, string $key): mixed# | A data key of an asset, or false. | |||
| method | localize(string $handle, string $name, array $data): bool# | Attaches a localized object to a script. | |||
| method | toPrint(): array# | Every queued handle not yet printed, dependencies first. @return list<string> @return list<string> | |||
| method | withPath(): 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 | |||
| method | unsource(string $handle): void# | Drops a handle's source so it prints as markup rather than a link. | |||
| method | markDone(string $handle): void# | Records a handle as printed. | |||
| method | item(string $handle): ?array# | One registered asset, or null. | |||
| method | items(): array# | Every registered asset. @return array<string, array<string, mixed>> | |||
| method | queue(): array# | The handles queued. @return list<string> | |||
| method | kind(): 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.
| private | settle(): void# | ||||
| private | changed(): void# | ||||
| private | defaults(): array# | @return array<string, array<string, list<string>>> | |||
| private | held(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. | |||
| private | ordered(array $start): array# |
@return list<string> |
Nothing matches.