文件名称:PHP快速需求路由FastRoute.zip
文件大小:19KB
文件格式:ZIP
更新时间:2022-08-06 00:15:08
开源项目
FastRoute 提供了一个快速实现基于路由的规则表达。示例代码:<?php require '/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; } 标签:FastRoute
【文件预览】:
FastRoute-master
----composer.json(895B)
----LICENSE(1KB)
----src()
--------Dispatcher()
--------functions.php(3KB)
--------RouteParser.php(1KB)
--------DataGenerator.php(734B)
--------Dispatcher.php(607B)
--------RouteCollector.php(4KB)
--------BadRouteException.php(126B)
--------DataGenerator()
--------Route.php(840B)
--------RouteParser()
----README.md(11KB)