Skip to content

codin/router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Router

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

Releases

No releases published

Packages

No packages published

Languages