codin / router
Just another router
dev-master
2021-10-25 16:01 UTC
Requires
- php: >=7.3
- psr/http-message: @stable
Requires (Dev)
- friendsofphp/php-cs-fixer: @stable
- phpspec/phpspec: @stable
- phpstan/phpstan: @stable
This package is auto-updated.
Last update: 2024-11-25 22:34:11 UTC
README
Simple routing component
$routes = new Router(); // RouterFactory::createFromPath('path/to/definitions'); $route = $routes->create('get', '/path/to/resource', 'controller@method'); $routes->append($route); // or shortcut $routes->get('/path/to/resource', 'controller@method'); // using grouping $routes->group([ 'prefix' => '/api', 'namespace' => 'API\\', ], static function ($routes) { $routes->get('/path/to/resource', 'controller@method'); }) $psr7request = new Request('post', 'foo/bar'); $matcher = new Matcher($routes); try { $route = $matcher->match($psr7request); } catch (Exceptions\RouteNotFound $e) { // do something with 404 } $route->getController(); // returns controller@method