Jasny Router is a versatile PSR-7 compatible router. It decouples the way to determine a route, from the routing and from running the routed action. The router supports double pass middleware.
The Jasny Router package is available on packagist. Install it using composer:
composer require jasny/router
use Jasny\Router;
use Jasny\Router\Routes\Glob as Routes;
use Jasny\HttpMessage\ServerRequest;
use Jasny\HttpMessage\Response;
$routes = new Routes([
'/' => function($request, $response) {
$response->getBody()->write('Hello world');
return $response;
},
]);
$router = new Router($routes);
$router->handle(new ServerRequest()->withGlobalEnvironment(), new Response());
When creating a Router
, you need to pass a object that implements the RoutesInterface
. Routes should be seen as a
collection of routes, with the ability to select one of those routes based on the server request.