mini\Dispatcher\HttpDispatcher
class
Documentation
HTTP request dispatcher
The HttpDispatcher is the entry point for HTTP requests. It:
- Creates PSR-7 ServerRequest from PHP globals
- Makes request available via mini\request()
- Delegates to RequestHandlerInterface (Router)
- Converts exceptions to HTTP responses
- 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)
Psr\Http\Message\ServerRequestInterface $currentServerRequest
array $middlewares
Event triggered before processing a request
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