hannesvdvreken/psr7-middlewares
最新稳定版本:0.1.0
Composer 安装命令:
composer require hannesvdvreken/psr7-middlewares
包简介
关键字:
README 文档
README
No longer maintained
Create callable middlewares instead. Signature:
function (RequestInterface $request, ResponseInterface $response, callable $next) { // Do something with the request before passing it on. ... // Pass on to next middleware. $response = $next($request, $response); // Do something with the response after the next middleware has been called. ... // Return ultimate response object. return $response; }
PSR-7 middlewares
Stackable middlewares for PSR-7 HTTP message objects.
Installation
composer require hannesvdvreken/psr7-middlewares
Description
This package is a small library that helps you to construct a decorated array of middlewares.
There are 2 types of middlewares:
A Kernel, which is a middleware which can pass on the Request and Response object to the next layer.
A Core object is usually the last layer of a list of middlewares.
A core will always return a PSR-7 ResponseInterface object and never pass on
the given RequestInterface object to a next layer. It will never have a next middleware set.
The Builder object helps in creating a composed Core which consists of a specified list of layers.
Note that the builder object is immutable:
thus it returns a different mutated object after each push and unshift call.
use Psr7Stack\Builder; $builder = new Builder(); $session = new SessionMiddleware(); $throttle = new TrottleMiddleware(); $app = new App(); $builder = $buider->push($session)->push($throttle)->push($app); $stack = $builder->resolve();
The returned Stack object can also be created with the static factory method create.
use Psr7Stack\Stack; $stack = Stack::create([$session, $throttle, $app]);
The Stack object itself is also a Core middleware, so it can be used in a different composition of middlewares. This is how you can send a Request object through the different layers of middlewares:
$psrResponse = $stack->handle($psrRequest);
Extending
Creating a Core yourself:
use Psr7Stack\Core; use Psr\Http\Message\RequestInterface; class App implements Core { /** * @param \Psr\Http\Message\RequestInterface $request * * @request \Psr\Http\Message\ResponseInterface */ public function handle(RequestInterface $request) { // Call the router and return the response. return $response; } }
Creating a Kernel:
use Psr7Stack\Kernel; use Psr7Stack\Traits\NextCore; class SessionMiddleware implements Kernel { // Use trait to implement the setNextCore method. use NextCore; /** * @param \Psr\Http\Message\RequestInterface $request * * @request \Psr\Http\Message\ResponseInterface */ public function handle(RequestInterface $request) { // Call the next core and return the response. $response = $this->next->handle($request); // Do something with the response and return it. ... return $response; } }
Middlewares
Existing
- League/route application core
Ideas for more middlewares
- Robots middleware. To return an environment specific robots.txt file.
- Any type of framework application
- Throttle middleware
- CORS middleware
- Cache middleware
- IP based Firewall middleware
- Logger middleware
Contributing
Contributions are welcome. See the contributions file to know how to contribute.
License
The MIT License (MIT). Please see License File for more information.
hannesvdvreken/psr7-middlewares 适用场景与选型建议
hannesvdvreken/psr7-middlewares 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 49 次下载、GitHub Stars 达 3, 最近一次更新时间为 2015 年 09 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「http」 「middleware」 「psr-7」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hannesvdvreken/psr7-middlewares 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hannesvdvreken/psr7-middlewares 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hannesvdvreken/psr7-middlewares 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
repository php library
Model of a web-based resource
Interfaces for web resource models and services to retrieve and create them
Interface for a factory to create Psr\Http\Message\StreamInterface objects
A PSR-7 compatible library for making CRUD API endpoints
统计信息
- 总下载量: 49
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 16
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-09