mrjulio / rapture-router
Rapture router component
v1.0.1
2017-11-18 20:59 UTC
Requires
- php: >=7.0.4
This package is not auto-updated.
Last update: 2024-11-02 15:04:28 UTC
README
A simple fork from the nikic/FastRoute implementation with reverse routing.
It implements the GroupCountBased
algorithm.
Requirements
- PHP v7.0
- php-pcre
Install
composer require mrjulio/rapture-router
Quick start
For more info check nikic/FastRoute
.
// add multiple routes $router = new \Rapture\Router\Router(); $router->addRoutes([ ['user-add', 'GET', '/user/add', 'User\Add'], ['user-edit', 'GET', '/user/edit/{id:\d+}[/{check}]', 'User\ViewDate'], ])->processRoutes(); // run once after each routes have been added // add group $router->addGroup( '/admin/user', [ ['search', 'GET', '/search', 'Search'], ['view', 'GET', '/view/{id:\d+}', 'View'], ], )->processRoutes(); // ...is same as... $router->addRoute('admin-user-search', 'GET', '/admin/user/search', 'Admin\User\Search'); $router->addRoute('admin-user-view', 'GET', '/admin/user/view/{id:\d+}', 'Admin\User\View') $router->processRoutes(); // [Router::FOUND, 'User\View', ['id' => 100]], $router->route('GET', '/user/edit/100'); // [Router::NOT_FOUND], $router->route('POST', '/user/edit/100'); // [Router::NOT_FOUND], $router->route('GET', '/user/edit/100/'); // trailing slash
About
Author
Iulian N. rapture@iuliann.ro
Testing
cd ./test && phpunit
Credits
License
Rapture PHP Router is licensed under the MIT License - see the LICENSE
file for details.