src/Dispatcher/functions.php
source
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Dispatcher Feature - Request lifecycle management |
| 5 | * |
| 6 | * The HttpDispatcher handles the complete HTTP request lifecycle: |
| 7 | * - Creates PSR-7 ServerRequest from globals |
| 8 | * - Delegates to RequestHandlerInterface (Router) |
| 9 | * - Converts exceptions to HTTP responses |
| 10 | * - Emits response to browser |
| 11 | */ |
| 12 | |
| 13 | namespace mini; |
| 14 | |
| 15 | use mini\Dispatcher\HttpDispatcher; |
| 16 | |
| 17 | /** |
| 18 | * Dispatch the current HTTP request |
| 19 | * |
| 20 | * Entry point for HTTP applications. Creates the dispatcher and handles the request. |
| 21 | * |
| 22 | * Usage: |
| 23 | * ```php |
| 24 | * // html/index.php |
| 25 | * <?php |
| 26 | * require __DIR__ . '/../vendor/autoload.php'; |
| 27 | * mini\dispatch(); |
| 28 | * ``` |
| 29 | * |
| 30 | * @return void |
| 31 | */ |
| 32 | function dispatch(): void |
| 33 | { |
| 34 | Mini::$mini->get(HttpDispatcher::class)->dispatch(); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * ============================================================================ |
| 39 | * Dispatcher Service Registration |
| 40 | * ============================================================================ |
| 41 | */ |
| 42 | |
| 43 | namespace mini\Dispatcher; |
| 44 | |
| 45 | use mini\Mini; |
| 46 | use mini\Lifetime; |
| 47 | |
| 48 | // Register HttpDispatcher service |
| 49 | Mini::$mini->addService(HttpDispatcher::class, Lifetime::Singleton, fn() => new HttpDispatcher()); |
| 50 |