jasny / router
A versatile router for PHP
Installs: 9 120
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 0
Forks: 2
Open Issues: 0
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.*
- dev-master
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-errorpage
- dev-strict-controller-class
- dev-controller-runner-namespace
- dev-determine-route-middleware
- dev-glob-stdclass-routes
- dev-controller-runner-notfound
- dev-middleware-path
- dev-docs
- dev-fix-tests
- dev-router-cleanup
- dev-glob-tests
- dev-runner
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.