Documentation

Kernel
in package
implements KernelInterface

AbstractYes

WordPress application kernel (framework {@see KernelInterface} implementation).

Mirrors the Moodle adapter kernel with one deliberate inversion: this class holds NO static state. Process-wide statics collide between plugins in one request (tests/Architecture/NoStaticMutableStateTest), so the singleton storage lives in the CONSUMER subclass — a static property on the product's own class is per-plugin state, because every plugin subclasses under its own namespace. For the same reason the Moodle boot seam (a static ContainerFactory::setBuilder()) becomes the abstract buildContainer() method: the product implements it, so this adapter never names a non-OSS container factory and never parks a closure in static state.

A product subclass provides two things:

final class AccountKernel extends Kernel
{
    private static ?self $kernel = null;

    protected static function kernel(): static
    {
        return self::$kernel ??= new static();
    }

    protected function buildContainer(): ContainerInterface
    {
        // Delegate to the container factory of its distribution tier.
    }
}

boot() wires the argument-free lib registrars onto the WordPress timeline whenever the product's container binds them — HookRegistrar and CronRegistrar on init (priority 5), RestRouteRegistrar on rest_api_init — the exact pattern every MIDDAG plugin used to hand-roll. Everything product-specific (admin menu tree, shared Inertia props, route definitions, integrations) belongs in onBoot().

Table of Contents

Interfaces

KernelInterface

Properties

$booted  : bool
$container  : ContainerInterface|null
$swappedInstances  : array<string, object>

Methods

container()  : ContainerInterface
The shared PSR-11 container.
dispatch()  : object
Dispatch an event through the framework's event dispatcher.
get()  : object
Resolve a service (facade/service-locator path).
handle()  : void
Execute the current wp-admin request through the admin routing surface.
init()  : void
Boot the kernel: build the product container and wire the timeline.
isBooted()  : bool
routing()  : RouterInterface
The adapter router bound by the product container.
shutdown()  : void
Reset kernel state (PHPUnit isolation): drops the container, swap map and booted flag so the next {@see init()} performs a fresh boot.
swap()  : void
Runtime override of a container entry (testing/facade swap), effective for {@see get()} lookups even after the container is compiled.
__construct()  : mixed
buildContainer()  : ContainerInterface
Build and compile the product's DI container.
kernel()  : static
Singleton storage, owned by the product subclass.
onBoot()  : void
Product wiring executed once per boot, after the standard timeline hooks are registered (admin menu tree, shared props, route definitions, integrations, ...).
boot()  : void
wireTimeline()  : void
Wire the argument-free lib registrars onto the WordPress hook timeline, resolving each from the product container only when bound.

Properties

$booted

private bool $booted = false

$container

private ContainerInterface|null $container = null

$swappedInstances

private array<string, object> $swappedInstances = []

runtime overrides (facade/test swap support)

Methods

container()

The shared PSR-11 container.

public static container() : ContainerInterface

Boots the kernel on first access.

Tags
throws
RuntimeException

when boot finished without a container

Return values
ContainerInterface

dispatch()

Dispatch an event through the framework's event dispatcher.

public static dispatch(object $event) : object
Parameters
$event : object
Tags
throws
RuntimeException

when no dispatcher is bound or dispatch fails

Return values
object

get()

Resolve a service (facade/service-locator path).

public static get(class-string|string $id) : object

Prefer constructor injection; this accessor exists for host boundaries that cannot receive dependencies (hook callbacks in legacy files, templates, WP-CLI glue).

Parameters
$id : class-string|string
Tags
throws
RuntimeException

when the service cannot be resolved

Return values
object

handle()

Execute the current wp-admin request through the admin routing surface.

public static handle() : void
Tags
throws
RuntimeException

when the product container does not bind AdminRouteRegistrar

init()

Boot the kernel: build the product container and wire the timeline.

public static init() : void

Idempotent — subsequent calls are no-ops until shutdown().

isBooted()

public static isBooted() : bool
Return values
bool

routing()

The adapter router bound by the product container.

public static routing() : RouterInterface
Tags
throws
RuntimeException

when the product container does not bind RouterInterface

Return values
RouterInterface

shutdown()

Reset kernel state (PHPUnit isolation): drops the container, swap map and booted flag so the next {@see init()} performs a fresh boot.

public static shutdown() : void

swap()

Runtime override of a container entry (testing/facade swap), effective for {@see get()} lookups even after the container is compiled.

public static swap(string $id, object $instance) : void
Parameters
$id : string
$instance : object

__construct()

protected final __construct() : mixed

buildContainer()

Build and compile the product's DI container.

protected abstract buildContainer() : ContainerInterface

Typically delegates to Middag\Framework\Kernel\ContainerFactory::build() with the product's BootstrapInterface (composing WpBootstrap), or to a proprietary factory from the product's distribution tier.

Return values
ContainerInterface

kernel()

Singleton storage, owned by the product subclass.

protected abstract static kernel() : static

A static property on the SUBCLASS is per-plugin state (each plugin subclasses under its own namespace), which is why this abstract exists instead of a static property here — see the class docblock.

Return values
static

onBoot()

Product wiring executed once per boot, after the standard timeline hooks are registered (admin menu tree, shared props, route definitions, integrations, ...).

protected onBoot(ContainerInterface $container) : void
Parameters
$container : ContainerInterface

wireTimeline()

Wire the argument-free lib registrars onto the WordPress hook timeline, resolving each from the product container only when bound.

private wireTimeline(ContainerInterface $container) : void
Parameters
$container : ContainerInterface
On this page

Search results