从请求到响应。一个包含三个阶段(准备、响应和关闭)的中间件栈
v1.0
2015-08-23 03:39 UTC
Requires
- php: >=5.4.0
- symfony/http-foundation: ~2.6
Requires (Dev)
- league/container: ~1.3
Suggests
- laasti/route: Provides routing middlewares using league/route
- league/container: Integration provided using ContainerResolver
This package is auto-updated.
Last update: 2024-09-20 23:18:58 UTC
README
具有三个阶段的中间件栈
- 准备阶段是您调整请求的地方;
- 响应阶段是您修改由准备阶段生成的响应的地方;
- 关闭阶段是您输出响应并关闭当前请求的地方(即关闭会话、发送电子邮件...);
Laasti\Stack有1个依赖项: symfony/http-foundation。我选择它是因为它以直接的方式处理请求和响应。我正在等待PSR7成熟,并最终将移除对HttpFoundation的依赖,改为使用PSR7标准。
它还提供了一个与League\Container的集成。
安装
composer require laasti/stack
用法
不使用League\Container
$stack = new Laasti\Stack\Stack;
//You must at least have one PrepareableMiddleware that returns a Response
$stack->push(new MyPrepareableMiddleware);
//Ouputs the response automatically
$stack->execute(Request::createFromGlobals());
使用League\Container
$container = new League\Container\Container;
$resolver = new Laasti\Stack\ContainerResolver($container);
$stack = new Laasti\Stack\Stack($resolver);
$container->add('MyPrepareableMiddleware');
//You must at least have one PrepareableMiddleware that returns a Response
$stack->push('MyPrepareableMiddleware');
//Ouputs the response automatically
$stack->execute(Request::createFromGlobals());
如果您遇到优先级问题,请确保您的中间件只定义了其中一种中间件类型。同时确保您的中间件尽可能少做工作,这样您就可以更容易地调整优先级。
贡献
- 分支它!
- 创建您的功能分支:
git checkout -b my-new-feature
- 提交您的更改:
git commit -am '添加一些功能'
- 将分支推送到远程:
git push origin my-new-feature
- 提交拉取请求 :D
历史
查看CHANGELOG.md以获取更多信息。
致谢
作者:Sonia Marquette (@nebulousGirl)
许可证
在MIT许可证下发布。查看LICENSE文件。