HttpKernelInterface#

Meritum\Http\HttpKernelInterface

Extends KernelInterface, RunnableKernelInterface, and Psr\Http\Server\RequestHandlerInterface. HttpKernel is the concrete implementation.

All methods inherited from KernelInterface are available.

Methods#

Routing#

public function addRoute(array|string $methods, string $uri, RequestHandlerInterface|string $handler): RouteInterface;

Registers a route. $methods is a single HTTP method string or an array of methods. $handler is either a RequestHandlerInterface instance or a class string to be resolved from the container at request time.

Returns a RouteInterface for further configuration (per-route middleware, etc.).

Throws KernelException if called after boot().


Middleware#

public function addMiddleware(MiddlewareInterface|string $middleware): static;

Adds a PSR-15 middleware to the global stack. Middleware runs in registration order. A class string is resolved from the container at request time.

Throws KernelException if called after boot().


Termination#

public function onTerminating(callable $callback): static;

Registers a callback to run after the response is emitted. Signature: callable(ServerRequestInterface, ResponseInterface, KernelInterface): void.

public function terminate(ServerRequestInterface $request, ResponseInterface $response): void;

Runs all registered terminating callbacks in order. Called automatically by run().


Request handling#

public function handle(ServerRequestInterface $request): ResponseInterface;

Passes the request through the middleware stack and router. If an exception escapes and ExceptionHandlerInterface is registered in the container, it is invoked. Otherwise the exception is re-thrown.

public function run(): int;

The main entry point. Resolves the request from globals, calls handle(), emits the response via SAPI, calls terminate(), then calls shutdown(). Returns 0.