jasny / router
This package is abandoned and no longer maintained.
The author suggests using the jasny/switch-route package instead.
A versatile router for PHP
v1.1.3
2020-01-16 15:40 UTC
Requires
- php: >=5.6.0
- jasny/php-functions: ^2.0|^3.0|^4.0
- psr/http-message: ^1.0
- psr/log: ^1.0
Requires (Dev)
- jasny/php-code-quality: 2.1.*
This package is auto-updated.
Last update: 2020-01-16 15:41:46 UTC
README
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.
Installation
The Jasny Router package is available on packagist. Install it using composer:
composer require jasny/router
Basic Usage
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());
Routes
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.