idiosyncratic / http-middlewarehandler
简单的 PSR-15 中间件处理器
1.0.2
2019-04-20 22:19 UTC
Requires
- php: >=7.3
- psr/http-message: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- doctrine/coding-standard: ^5.0
- nyholm/psr7: ^1.1
- phpstan/phpstan: ^0.11.2
- phpstan/phpstan-phpunit: ^0.11.0
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-08-25 08:23:32 UTC
README
简单的基于队列的 PSR-15 中间件处理器。
安装
composer require idiosyncratic/http-middlewarehandler
使用
创建实例需要
- 一个实现
Psr\Http\Server\RequestHandlerInterface
的回退请求处理器 - 一个或多个实现
Psr\Http\Server\MiddlewareInterface
的中间件
use Idiosyncratic\Http\Middleware\MiddlewareRequestHandler;
$handler = new MiddlewareRequestHandler(
new PsrRequestHandler(),
new PsrMiddlewareOne(),
new PsrMiddlewareTwo(),
new PsrMiddlewareThree(),
);
$response = $handler->handle($psrServerRequest);
虽然大多数 PHP 应用程序设计为脚本生命周期为单个请求,但 MiddlewareRequestHandler
被设计为可以在长期运行的脚本中使用,例如使用 ReactPHP 或类似库构建的应用程序。因此,预计中间件以及它们所使用的服务是无状态的,因为单个实例可能服务于多个请求。