borschphp/router

A FastRoute router implementation.

0.1.1 2022-02-19 16:26 UTC

This package is auto-updated.

Last update: 2022-05-19 18:09:37 UTC


README

Build Status Latest Stable Version License

A FastRoute router implementation, inspired by the one you can find in the excellent Mezzio Routing Interfaces.
The router is based on nikic/fastroute request router.

You need to provide a PSR-7 ServerRequestInterface in order to match the routes.
A PSR-7 ResponseInterface must be returned by the route handler.

Installation

Via composer :

composer require borschphp/router

Usage

require_once __DIR__.'/vendor/autoload.php';

$router = new \Borsch\Router\FastRouteRouter();

$router->addRoute(new \Borsch\Router\Route(
    ['GET'],
    '/articles/{id:\d+}[/{title}]',
    new HomeHandler(), // Instance of RequestHandlerInterface
    'test'
));

$server_request = \Laminas\Diactoros\ServerRequestFactory::fromGlobals();

$route_result = $router->match(\Laminas\Diactoros\ServerRequestFactory::fromGlobals());

// $route_result is an instance of RouteResultInterface
$response = $route_result->getMatchedRoute()->getHandler()->handle($server_request);

// Send the response back to the client or other...

License

The package is licensed under the MIT license. See License File for more information.