mamadou-aly-sy / router
A simple php router
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/mamadou-aly-sy/router
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-09-18 19:19:07 UTC
README
A simple php router
Requirements
- PHP version:
>=8.0
Initialization
<?php require_once './vendor/autoload.php'; $router = new \MamadouAlySy\Router( new \MamadouAlySy\RouteCollection() );
Routes Registration
$router->get('/', function () {/**/}); $router->post('/', function () {/**/}); $router->put('/', function () {/**/}); $router->delete('/', function () {/**/}); $router->any('/', function () {/**/});
Matching Routes
$route = $router->match('GET', '/'); // => returns a route if match or null if not match $route->getName(); // => returns the route name $route->getAction(); // => returns the route action $route->getParameters(); // => returns the route matched parameters
Dynamic Routes
$router->get('/user/:id', function () {/**/})->with('id', '[0-9]+'); $router->get('/:action/:name', function () {/**/});
Generating route url
$router->get('/edit/:id', function () {/**/}, 'app.edit'); $router->generateUri('app.edit', [id => 2]); // => returns /edit/2