mini\Dispatcher\HttpDispatcher class

Documentation

HTTP request dispatcher

The HttpDispatcher is the entry point for HTTP requests. It:

  1. Creates PSR-7 ServerRequest from PHP globals
  2. Makes request available via mini\request()
  3. Delegates to RequestHandlerInterface (Router)
  4. Converts exceptions to HTTP responses
  5. Emits response to browser

Architecture: HttpDispatcher (request lifecycle) → RequestHandlerInterface (Router) → Controllers

Exception handling: Exceptions thrown during request handling are converted to ResponseInterface using a separate exception converter registry. This allows registering specific exception handlers without polluting the main converter registry.

Usage:

// html/index.php
Mini::$mini->get(HttpDispatcher::class)->dispatch();

Register exception converters:

// bootstrap.php
$dispatcher = Mini::$mini->get(HttpDispatcher::class);
$dispatcher->registerExceptionConverter(function(NotFoundException $e): ResponseInterface {
    return new Response(404, ['Content-Type' => 'text/html'], render('404'));
});

Properties (5)

private mini\Converter\ConverterRegistryInterface $exceptionConverters
private ?Psr\Http\Message\ServerRequestInterface $currentServerRequest
private array $middlewares
public readonly mini\Hooks\Event $onBeforeRequest

Event triggered before processing a request

public readonly mini\Hooks\Event $onAfterRequest

Event triggered after processing a request (in finally block)

Methods (15)

Documentation missing

Add middleware to the request pipeline

Register an exception converter

Dispatch the current HTTP request

Build middleware chain wrapper around the final handler

Install request global proxies for fiber-safe request handling

Emit a PSR-7 response to the browser

Handle fatal errors when no exception converter is registered

Render detailed error page for debug mode

Render simple error page for production

Get source code context around the error line

Create ServerRequest from PHP superglobals

Extract headers from $_SERVER

Normalize $_FILES array to UploadedFileInterface instances

Create UploadedFile instance from $_FILES specification

Source

src/Dispatcher/HttpDispatcher.php:45-754