jerowork / middleware-request-handler
此包已被废弃,不再维护。没有建议的替代包。
基于PSR-15的简约中间件请求处理器(分发器)
0.5.0
2019-04-05 19:23 UTC
Requires
- php: ^7.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- phpunit/phpunit: ^6.5 || ^7.0 || ^8.0
- zendframework/zend-diactoros: ^1.7 || ^2.0
Suggests
- zendframework/zend-diactoros: As PSR-7 implementation
Provides
README
基于PSR-15的简约中间件请求处理器(分发器)。
安装
通过Composer安装
$ composer require jerowork/middleware-request-handler
用法
与PSR-7请求实现一起使用,例如 Zend Diactoros。
示例
use Jerowork\MiddlewareDispatcher\Middleware\FinalResponseMiddleware; use Jerowork\MiddlewareDispatcher\MiddlewareRequestHandler; use Zend\Diactoros\Response; use Zend\Diactoros\Response\SapiEmitter; use Zend\Diactoros\ServerRequestFactory; // Setup a list of PSR-15 middlewares $middlewares = [ new SomeMiddleware(), new AnotherMiddleware() ]; // Setup request handler $handler = new MiddlewareRequestHandler($middlewares); // Add other middlewares after construct $handler->addMiddleware( new ThirdMiddleware(), new FourthMiddleware() ); // Add final reversal order middleware $handler->addMiddleware(new FinalResponseMiddleware(new Response()); // Handle a PSR-7 server request to response by the request handler (PSR-15) $response = $handler->handle(ServerRequestFactory::fromGlobals()); // Output PSR-7 response with a response emitter implementation of your choice (new SapiEmitter())->emit($response);