tgrj/tweb_dispatch
最新稳定版本:v1.0.2
Composer 安装命令:
composer require tgrj/tweb_dispatch
包简介
minimalistic router
关键字:
README 文档
README
minimalistic router
Background
I used noodlehaus/dispatch for routing, but wanted the feature to have routes be declarable as static class method attributes instead for convenience. Thus I forked the original code and extended all with some kind of "reflection layer".
Usage
Basically with this it should be possible to define routes as attributes on static class methods, as if if were the original route() method (method, uri path and middleware, while the final function would be the static method itself on which the attribute is attached).
Example:
class IndexController {
#[Route('GET', '/')]
public static function index(): callable
{
return response('index page');
}
#[Route('GET', '/item/:id', ['Middleware::auth'])]
public static function index(array $params): callable
{
return response('item-id: ' . ($params['id'] ?? 'fail'));
}
}
In the bootstrap (in my case it's the entry index.php file) you have to register the classes, which hold the attributes and finally use the dispatch() method as if it just were noodlehaus/dispatch:
tweb_add_routes_controllers(IndexController::class, ...);
dispatch();
Licence
noodlehaus/dispatch is under MIT licence, so is this repo as well!
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-07