dakujem/generic-middleware
最新稳定版本:1.0
Composer 安装命令:
composer require dakujem/generic-middleware
包简介
Generic PSR-15 implementation: Turns callables into Handlers and Middleware.
关键字:
README 文档
README
💿
composer require dakujem/generic-middleware
Contains a couple of classes:
GenericMiddleware, an implementation ofPsr\Http\Server\MiddlewareInterfaceGenericHandler, an implementation ofPsr\Http\Server\RequestHandlerInterface
Note that I'm using aliases
Request,ResponseandHandlerfor their respective PSR interface names for brevity.Consider the following
usestatements in use:use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Server\RequestHandlerInterface as Handler;
GenericMiddleware
The GenericMiddleware is a general purpose middleware that turns a callable into a PSR-15 implementation.
It accepts any callable with signature fn(Request,Handler):Response.
It can be used for convenient inline middleware implementation:
$app->add(new GenericMiddleware(function(Request $request, Handler $next): Response { $request = $request->withAttribute('foo', 42); $response = $next->handle($request); return $response->withHeader('foo', 'bar'); }));
GenericHandler
The GenericHandler is a general purpose request handler, as per the PSR-15 specification.
It turns a callable with signature fn(Request):Response into a PSR-15 implementation.
It can be used for convenient inline handler implementation where you don't want to bother with neither anonymous classes nor named classes:
$kernel = new GenericHandler( fn() => new Response(404, 'Not Found') ); $dispatcher = new MiddlewareDispatcher($kernel);
Testing
Run unit tests using the following command:
$ composer test
Contributing
Ideas, feature requests and other contribution is welcome. Please send a PR or create an issue.
统计信息
- 总下载量: 4.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Unlicense
- 更新时间: 2020-11-28