A simple PHP router that utilizes nikic/FastRoute.
composer require bulldog/router
<?php
use Bulldog\Router;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\ServerRequestFactory;
// You'll usually use the line below, but to demonstrate, we will create our own request.
// $request = ServerRequestFactory::fromGlobals();
$request = new ServerRequest([], [], '/', 'GET');
$router = new Router;
$router->addRoute('get', '/', 'callable');
$router->run($request);
echo $router->handler();
// callable
var_dump($router->vars());
// array(0) {
// }
<?php
use Bulldog\Router;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\ServerRequestFactory;
// You'll usually use the line below, but to demonstrate, we will create our own request.
// $request = ServerRequestFactory::fromGlobals();
$request = new ServerRequest([], [], '/user/1', 'GET');
$router = new Router;
$router->addRoute('get', '/user/{id}', 'callable');
$router->run($request);
echo $router->handler();
// callable
var_dump($router->vars());
// array(1) {
// 'id' =>
// string(1) "1"
// }
All contributions welcome! Please first create an issue if something is wrong and let us know if you intend to fix it. Then fork the repo, create a new branch, and work on the issue. The branch name should be relevant to the issue.
Run php-cs-fixer
with the default rules.
php-cs-fixer fix ./src