colossal/colossal-middleware-queue
最新稳定版本:v1.0.2
Composer 安装命令:
composer require colossal/colossal-middleware-queue
包简介
A PSR-15 middleware allowing multiple other PSR-15 middleware to be treated as a single entity.
关键字:
README 文档
README
A PSR-15 middleware allowing multiple other PSR-15 middleware to be treated as a single entity.
Usage
namespace Dummy; use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface }; use Psr\Http\Server\{ MiddlewareInterface, RequestHandlerInterface }; class DummyMiddlewareA { public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { echo 'A'; return $handler->handle($request); } } class DummyMiddlewareB { public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { echo 'B'; return $handler->handle($request); } } class DummyHandler { public function handle(ServerRequestInterface $request): ResponseInterface { echo 'Handler'; // Return a ResponseInterface } }
// ---------------------------------------------------------------------------- // // Creating and using the MiddlewareQueue is trivial. // // ---------------------------------------------------------------------------- // use Colossal\MiddlewareQueue\MiddlewareQueue; use Dummy\{ DummyMiddlewareA, DummyMiddlewareB, DummyHandler }; $dummyMiddlewareA = new DummyMiddlewareA(); $dummyMiddlewareB = new DummyMiddlewareB(); $middlewareQueue = new MiddlewareQueue(); $middlewareQueue->enqueue($dummyMiddlewareA); $middlewareQueue->enqueue($dummyMiddlewareB); // ---------------------------------------------------------------------------- // // The resulting MiddlewareQueue can now be used as a single middleware. // // A call to process will now do the following (in order): // // - Call $dummyMiddlewareA->process() passing the request passed to // // $middlewareQueue->process(). // // - Call $dummyMiddlewareB->process() passing the request passed to // // $middlewareQueue->process(). // // - Call RequestHandlerInterface::handle() on the handler passed to // // $middlewareInterface->process(). // // ---------------------------------------------------------------------------- // $middlewareQueue->process($request, $dummyHandler); // Prints: // A // B // Handler
Development Tips
Running PHPStan Code Quality Analysis
Run the PHPStan code quality analysis with the following command:
>> .\vendor\bin\phpstan --configuration=phpstan.neon
Running PHP Code Sniffer Code Style Analysis
Run the PHP Code Sniffer code style analysis with the following commands:
>> .\vendor\bin\phpcs --standard=phpcs.xml src
To fix automatically resolve issues found by PHP Code Sniffer run the following commands:
>> .\vendor\bin\phpcbf --standard=phpcs.xml src
统计信息
- 总下载量: 38
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-05