ckunkle / httpassage
一个简单、灵活的路由和PSR-7消息处理库
1.0.1
2021-03-02 12:46 UTC
Requires
- php: >=7
- altorouter/altorouter: ^2
- psr/http-message: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- guzzlehttp/psr7: ^1.7
- phpunit/phpunit: ^4
This package is auto-updated.
Last update: 2024-09-11 21:31:26 UTC
README
一个简单、灵活的路由和PSR-7 HTTP消息处理库。
特性
- 基于 AltoRouter 的HTTP请求路由
- 与任何 PSR-7 实现兼容
- 可定制的回调系统用于处理请求和响应
- 默认兼容 PSR-15 中间件和请求处理器
安装
composer require ckunkle/httpassage
快速入门
此示例使用 guzzlehttp/psr7 作为PSR-7实现,但任何PSR-7实现在这里都适用。
<?php require __DIR__ . "/vendor/autoload.php"; /** * Create an instance of Context by passing a PSR-7 ServerRequest * and a PSR-7 response to the constructor */ new \HTTPassage\Context( \GuzzleHttp\Psr7\ServerRequest::fromGlobals(), new \GuzzleHttp\Psr7\Response() ); /** * Create a Router instance and map some routes */ $router = new \HTTPassage\Router(); $router->get("/my/example/[a:route]", function($context) { $route = $context->getRouteParamater("route"); $context->getResponse()->getBody()->write("You have reached $route!"); return $context; }); /** * Route the Context */ $context = $router->route($context);