Nexus API Reference

CompiledHttpApp
in package
implements RequestHandlerInterface

Read onlyYes
FinalYes

Immutable, ready-to-serve PSR-15 request handler produced by {@see HttpApp::compile()}.

CompiledHttpApp is the result of freezing an HttpApp DSL. It holds the fully assembled middleware pipeline (exception handler → global middleware → router) compiled once at boot time. The handle() method invokes that chain directly with no per-request stack allocation.

Server adapters (Swoole HTTP server, Fiber-based development server, etc.) receive a CompiledHttpApp and call handle() for every incoming request. Application code should never need to construct or call this class directly.

PSR-14 lifecycle events are emitted when an EventDispatcherInterface is wired during HttpApp::create():

  • RequestStarted — emitted before the middleware chain is invoked.
  • RequestCompleted — emitted after the response is produced, carrying elapsed nanoseconds.

Example — handing the compiled app to a server adapter:

$compiled = HttpApp::create($system)->get('/ping', PingHandler::class)->compile();

// Swoole HTTP server adapter:
$server->on('request', static function ($req, $res) use ($compiled): void {
    $response = $compiled->handle(PsrFactory::fromSwoole($req));
    // write $response back to $res …
});
Tags
see
HttpApp

The DSL that produces CompiledHttpApp via compile()

see
RequestStarted

PSR-14 event emitted at request start

see
RequestCompleted

PSR-14 event emitted after response is produced

psalm-api

Table of Contents

Interfaces

RequestHandlerInterface

Methods

__construct()  : mixed
handle()  : ResponseInterface
Dispatch the request through the compiled middleware pipeline.

Methods

__construct()

public __construct(RequestHandlerInterface $compiledHandler, EventDispatcherInterface|null $events) : mixed
Parameters
$compiledHandler : RequestHandlerInterface
$events : EventDispatcherInterface|null

handle()

Dispatch the request through the compiled middleware pipeline.

public handle(ServerRequestInterface $request) : ResponseInterface

Emits RequestStarted and RequestCompleted PSR-14 events when an EventDispatcherInterface was supplied at build time. When no dispatcher is present the overhead is a single null identity check.

Parameters
$request : ServerRequestInterface

The incoming PSR-7 server request.

Return values
ResponseInterface

The produced HTTP response.


        
On this page

Search results