FastRoute は、ルートベースのルール式を迅速に実装します。
サンプルコード:
<?phprequire '/path/to/FastRoute/src/bootstrap.php';$dispatcher = FastRoute\simpleDispatcher(function(FastRoute\RouteCollector $r) { $r->addRoute('GET', '/user/{id:\d+}', 'handler1'); $r->addRoute('GET', '/user/{id:\d+}/{name}', 'handler2'); // Or alternatively $r->addRoute('GET', '/user/{id:\d+}[/{name}]', 'common_handler');});$routeInfo = $dispatcher->dispatch($httpMethod, $uri);switch ($routeInfo[0]) { case FastRoute\Dispatcher::NOT_FOUND: // ... 404 Not Found break; case FastRoute\Dispatcher::METHOD_NOT_ALLOWED: $allowedMethods = $routeInfo[1]; // ... 405 Method Not Allowed break; case FastRoute\Dispatcher::FOUND: $handler = $routeInfo[1]; $vars = $routeInfo[2]; // ... call $handler with $vars break;}
プロジェクトホームページ: http://www.open-open.com/lib/view/home/1437228582428