pollen-solutions / routing
Pollen Solutions - Routing Component - HTTP request mapping and HTTP response resolution.
v1.0.10
2023-01-04 00:00 UTC
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- laminas/laminas-diactoros: ^2.5
- laminas/laminas-httphandlerrunner: ^2.0
- league/route: ^5.0
- nyholm/psr7: ^1.3
- pollen-solutions/argument-resolver: ^1.0
- pollen-solutions/http: ^1.0
- pollen-solutions/support: ^1.0
- pollen-solutions/view: ^1.0
Requires (Dev)
- phpunit/phpunit: ^9.0
- roave/security-advisories: dev-latest
Suggests
- pollen-solutions/container: Pollen Solutions - Container Component - PSR-11 ready Dependencies Injection Container.
README
Pollen Solutions Routing Component provide a layer of HTTP request mapping and HTTP response resolution.
Installation
composer require pollen-solutions/routing
Basic Usage
<?php declare(strict_types=1); use Pollen\Http\Request; use Pollen\Http\Response; use Pollen\Http\ResponseInterface; use Pollen\Routing\Router; // Router instantiation $router = new Router(); // Map a route $router->map('GET', '/', static function (): ResponseInterface { return new Response('<h1>Hello, World!</h1>'); }); $router->map('GET', '/phpinfo', static function () { ob_start(); phpinfo(); return new Response(ob_get_clean()); }); // Setting Handle Request (optional) $psrRequest = Request::createFromGlobals()->psr(); // Map a Fallback Route (optional) $router->setFallback(function () { return new Response('<h1>404 - Page not found !</h1>', 404); }); // Catch HTTP Response $response = $router->handle($psrRequest); // Send the response to the browser $router->send($response); // Trigger the terminate event $router->terminate($psrRequest, $response);