Skip to content
This repository has been archived by the owner on Jun 22, 2020. It is now read-only.

jasny/router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jasny Router

Build Status Scrutinizer Code Quality Code Coverage SensioLabsInsight Packagist Stable Version Packagist License

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.