middlewares / uuid
中间件用于生成一个UUID并将其保存在X-Uuid头部
v2.0.1
2023-08-11 18:52 UTC
Requires
- php: ^7.2 || ^8.0
- psr/http-server-middleware: ^1.0
- ramsey/uuid: ^3.5 || ^4.7
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- laminas/laminas-diactoros: ^2.3
- middlewares/utils: ^3.0
- oscarotero/php-cs-fixer-config: ^1.0
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^8|^9
- squizlabs/php_codesniffer: ^3.0
README
中间件用于生成一个UUID(通用唯一标识符)并将其保存在请求和响应的X-Uuid
头部。这对于调试非常有用。
生成的UUID与RFC 4122版本4兼容,使用ramsey/uuid实现。
要求
- PHP >= 7.2
- 一个PSR-7 http库
- 一个PSR-15中间件分发器
安装
此包可以通过Composer安装和自动加载,名称为middlewares/uuid。
composer require middlewares/uuid
使用
Dispatcher::run([ new Middlewares\Uuid(), function ($request) { //Get the UUID from the request echo $request->getHeaderLine('X-Uuid'); } ]); //Get the UUID from the response echo $response->getHeaderLine('X-Uuid');
头部
此选项允许配置头部名称。默认为X-Uuid
。
$uuid = (new Middlewares\Uuid())->header('X-Request-Id');
有关最近更改的更多信息,请参阅CHANGELOG,有关贡献详情,请参阅CONTRIBUTING。
MIT许可(MIT)。有关更多信息,请参阅LICENSE。