gamringer/pipe
Composer 安装命令:
composer require gamringer/pipe
包简介
PSR-15 HTTP Middleware Dispatcher
README 文档
README
A PSR-15 handler with no assumption
License
Pipe is licensed under the MIT license.
Installation
$ composer require gamringer/pipe
Tests
$ composer install $ phpunit
Documentation
These are all the various ways in which Pipe can be used. These examples can be found in the examples directory. First, let the following code simply be assumed present in all examples:
<?php declare(strict_types=1); include __DIR__.'/../vendor/autoload.php'; use GuzzleHttp\Psr7\ServerRequest; use GuzzleHttp\Psr7\Response; use gamringer\Pipe\Pipe; use gamringer\Pipe\Example\StaticMiddleware; // Request to be handled later $request = new ServerRequest('GET', '/'); // For use in this example, we build a few Middleware objects // One that simply returns a predetermined response in all cases $staticResponse = new Response(); $staticResponseMiddleware = new StaticMiddleware($staticResponse); // One that echoes it's constructor argument before passing to the next one. $fooMiddleware = new FooMiddleware('1');
Create pipe from an array of Middlewares
// Build Pipe from an array of Middlewares $pipe = new Pipe([ $staticResponseMiddleware, ]); // Use Pipe via RequestHandlerInterface $response = $pipe->handle($request);
Create an empty pipe and add Middlewares dynamically
// Build empty Pipe $pipe = new Pipe(); // Add Middlewares dynamically $pipe->push($staticResponseMiddleware); // Use Pipe via RequestHandlerInterface $response = $pipe->handle($request);
Stack many Middlewares dynamically
// Build empty Pipe $pipe = new Pipe(); // Add Middlewares dynamically $pipe->push($fooMiddleware); $pipe->push($staticResponseMiddleware); // Use Pipe via RequestHandlerInterface $response = $pipe->handle($request);
Use pipe as a Middleware
Pipe can also be used via the MiddlewareInterface by pushing it into another Pipe
// Build empty Pipe $pipe = new Pipe(); // Add Middlewares dynamically $pipe->push($fooMiddleware); $pipe->push(new Pipe([ new FooMiddleware('2') ])); $pipe->push($staticResponseMiddleware); // Use Pipe via RequestHandlerInterface $response = $pipe->handle($request);
Running out of Middlewares
If it runs out of middlewares to call, Pipe will respond differently depending on the way it was called.
As a RequestHandler
Most applications will be using Pipe as a RequestHandler to stack Middlewares and handle user requests. If the request goes through the Pipe and the last Middleware attempts to delegate to the next one, a TerminalException is raised. The same logic also covers the empty Pipe case:
$pipe = new Pipe(); $pipe->handle($request); // Throws new \gamringer\Pipe\TerminalException()
As a Middleware
If called as a Middleware, when running out of Middlewares itself, it will simply pass along to its next sibling:
// Build empty Pipe $pipe = new Pipe(); // Add Middlewares dynamically $pipe->push($fooMiddleware); $pipe->push(new Pipe([ new FooMiddleware('2') ])); $pipe->push(new Pipe()); $pipe->push($staticResponseMiddleware); // Use Pipe via RequestHandlerInterface $response = $pipe->handle($request);
gamringer/pipe 适用场景与选型建议
gamringer/pipe 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 180 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 10 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 gamringer/pipe 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gamringer/pipe 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 180
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-01