KernelInterface#

Georgeff\Kernel\KernelInterface

The primary contract for interacting with the kernel. Kernel is the concrete implementation; meritum/http and meritum/cli extend it with HttpKernelInterface and CliKernelInterface respectively.

Methods#

Boot control#

public function boot(): void;

Runs the full boot sequence. Throws if already booted.

public function shutdown(): void;

Runs shutdown callbacks. No-op if already shutdown or not yet booted.

public function isBooting(): bool;

Returns true during the boot sequence (between preBoot and postBoot).

public function isBooted(): bool;

Returns true after boot() completes.

public function isShutdown(): bool;

Returns true after shutdown() completes.


Lifecycle hooks#

public function onBooting(callable $callback): static;

Registers a callback to run at the start of boot(), before any modules are loaded. The callback receives KernelInterface.

public function onBooted(callable $callback): static;

Registers a callback to run after boot() completes. The callback receives KernelInterface.

public function onShutdown(callable $callback): static;

Registers a callback to run at the start of shutdown(). The callback receives KernelInterface.

public function afterShutdown(callable $callback): static;

Registers a callback to run after shutdown() completes. The callback receives KernelInterface.

Multiple callbacks can be registered for each hook; they run in registration order.


Service definitions#

public function define(string $id, callable $factory): DefinitionInterface;

Registers a service definition and returns a DefinitionInterface for further configuration. The factory signature is callable(ContainerInterface): mixed.

Throws KernelException if called after boot() or if $id is a reserved service.

public function tag(string $id, array $tags): static;

Adds tags to an already-defined service. $tags is a string[]. Silent no-op if $id has not been defined.

public function decorate(string $id, callable $decorator): static;

Wraps an existing service. The decorator signature is callable(mixed $inner, ContainerInterface $c): mixed.

Throws KernelException if called after boot() or if $id is a reserved service.

public function override(string $id, callable $factory, bool $preserve = false): DefinitionInterface;

Replaces an existing service definition outright, returning a DefinitionInterface for further configuration. Applied in a dedicated boot phase that runs after all modules have registered but before decoration, so an override registered before boot always wins — even against a module that defines the same service during its own register().

Unlike decorate(), does not inherit the original definition’s shared flag, aliases, or tags by default; pass preserve: true to copy them onto the override.

Throws KernelException if called after boot(), if $id is a reserved service, or (at boot time) if no definition exists for $id to override.


Module registration#

public function addModule(ModuleInterface $module): static;

Registers a single module. Throws KernelException if the same class has already been added, or if called after boot has started.

public function addRepository(ModuleRepositoryInterface $repository): static;

Registers a module repository. Throws KernelException if called after boot has started.


Container and environment#

public function getContainer(): \Psr\Container\ContainerInterface;

Returns the PSR-11 container. Only available after boot().

public function getEnvironment(): string;

Returns the current environment as a string ('local', 'production', 'staging', 'development', 'testing').

public function isDebug(): bool;

Returns true if debug mode is enabled.

public function getStartTime(): float;

Returns the kernel’s construction timestamp. Returns -INF unless debug mode is enabled.


Reserved services#

The following service IDs cannot be overwritten via define() or wrapped via decorate():

ID Resolves to
KernelInterface::class The kernel instance
'kernel' Alias for KernelInterface::class
DI\TagRegistryInterface::class The tag registry
'kernel.tag.registry' Alias for TagRegistryInterface::class
'kernel.debug' bool — debug mode flag
'kernel.environment' string — environment value

'kernel.config' is also reserved and registered during boot from module config() contributions.