middlewares / uuid
Middleware to generate an UUID and save it in the X-Uuid header
Installs: 17 991
Dependents: 3
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 0
Open Issues: 1
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
Middleware to generate an UUID (Universally Unique Identifiers) and save it in the X-Uuid
header of the request and response. Useful for debugging purposes.
The UUID generated is compatible with RFC 4122 version 4 using ramsey/uuid for that.
Requirements
- PHP >= 7.2
- A PSR-7 http library
- A PSR-15 middleware dispatcher
Installation
This package is installable and autoloadable via Composer as middlewares/uuid.
composer require middlewares/uuid
Usage
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');
header
This option allows to configure the header name. By default is X-Uuid
.
$uuid = (new Middlewares\Uuid())->header('X-Request-Id');
Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.
The MIT License (MIT). Please see LICENSE for more information.