bulldog / router
PHP Router
v0.1.0
2018-08-11 20:25 UTC
Requires
- bulldog/router-interface: ^2.0
- nikic/fast-route: ^1.3
Requires (Dev)
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^7.3
- zendframework/zend-diactoros: ^1.8
Provides
- bulldog/router-interface: ^1.0
This package is auto-updated.
Last update: 2024-11-05 18:22:59 UTC
README
A simple PHP router that utilizes nikic/FastRoute.
Installation
composer require bulldog/router
Usage
<?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) { // }
With Array Parameters
<?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" // }
Contributing
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.
Style
Run php-cs-fixer
with the default rules.
php-cs-fixer fix ./src