2017 © Pedro Peláez
 

library request-id

Request Id middleware with PSR-7

image

php-middleware/request-id

Request Id middleware with PSR-7

  • Tuesday, July 24, 2018
  • by snapshotpl
  • Repository
  • 3 Watchers
  • 15 Stars
  • 27,915 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 14 Versions
  • 7 % Grown

The README.md

Request ID middleware for PHP

Build Status, (*1)

PSR-7 Request ID middleware, (*2)

This middleware provide framework-agnostic possibility to generate and add to request/response's header Request ID (Correlation ID)., (*3)

Installation

composer require php-middleware/request-id

Usage

This middleware require in contructor PhpMiddleware\RequestId\RequestIdProviderFactoryInterface implementation which must create a new RequestIdProviderInterface object. We provide RequestIdProvider default implementation., (*4)

$generator = new PhpMiddleware\RequestId\Generator\PhpUniqidGenerator();
$requestIdProvider = new PhpMiddleware\RequestId\RequestIdProviderFactory($generator);
$requestIdMiddleware = new PhpMiddleware\RequestId\RequestIdMiddleware($requestIdProvider);

$app = new MiddlewareRunner();
$app->add($requestIdMiddleware);
$app->run($request, $response);

All Provider factory constructor options:, (*5)

  • PhpMiddleware\RequestId\Generator\GeneratorInterface $generator - generator implementation (required)
  • bool|PhpMiddleware\RequestId\OverridePolicy\OverridePolicyInterface $allowOverride (default true) - if true and request id header exists in incoming request, then value from request header will be used in middleware, using generator will be avoid
  • string $requestHeader (default X-Request-Id) - request header name

How to get request id in my application?, (*6)

  • Middleware implements RequestIdProviderInterface, so you are able to use getRequestId() method,
  • from request-id attribute in ServerRequest object ($request->getAttribute(RequestIdMiddleware::ATTRIBUTE_NAME)).

Override policy

You can add your own logic to decide when override incoming request id. You can implement OverridePolicyInterface and pass it as $allowOverride variable in constructor., (*7)

Monolog processor

We provide simple Monolog processor to add request it to every log entry!, (*8)

Request decorator

RequestDecorator adds header with request id to your request object. It's useful when your microservices communicate between using PSR-7 HTTP messages e.g. Guzzle., (*9)

Request Id generators

To generate request id you need to use implementation of PhpMiddleware\RequestId\Generator\GeneratorInterface. There are predefined generators in PhpMiddleware\RequestId\Generator\ namespace:, (*10)

PhpUniqidGenerator

Simple generator using uniqid function., (*11)

RamseyUuid1Generator

UUID1 implementations of Ramsey\Uuid. To use it you need to add ramsey/uuid dependency to your composer.json., (*12)

RamseyUuid3Generator

UUID3 implementations of Ramsey\Uuid. To use it you need to add ramsey/uuid dependency to your composer.json., (*13)

RamseyUuid4Generator

UUID4 implementations of Ramsey\Uuid. To use it you need to add ramsey/uuid dependency to your composer.json., (*14)

RamseyUuid4StaticGenerator

Generates Uuid4 like RamseyUuid4Generator however it's not require any dependency (it use static factory method)., (*15)

RamseyUuid5Generator

UUID5 implementations of Ramsey\Uuid. To use it you need to add ramsey/uuid dependency to your composer.json., (*16)

PrefixedGenerator

It adds prefix to generated request id., (*17)

Md5Generator

This generator converts generated request id to md5 hash., (*18)

It's just works with any modern php framework!

Middleware tested on: * Expressive, (*19)

Middleware should works with: * Slim 3.x, (*20)

And any other modern framework supported middlewares and PSR-7., (*21)

The Versions

24/07 2018

dev-php72-support

dev-php72-support

Request Id middleware with PSR-7

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr psr-7 request-id

13/05 2017

dev-master

9999999-dev

Request Id middleware with PSR-7

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr psr-7 request-id

13/05 2017

3.1.1

3.1.1.0

Request Id middleware with PSR-7

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr psr-7 request-id

13/05 2017

dev-license

dev-license

Request Id middleware with PSR-7

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr psr-7 request-id

12/05 2017

3.1.0

3.1.0.0

Request Id middleware with PSR-7

  Sources   Download

The Requires

 

The Development Requires

middleware psr psr-7 request-id

30/03 2016

3.0.2

3.0.2.0

Request Id middleware with PSR-7

  Sources   Download

The Requires

 

The Development Requires

middleware psr psr-7 request-id

23/03 2016

3.0.1

3.0.1.0

Request Id middleware with PSR-7

  Sources   Download

The Requires

 

The Development Requires

middleware psr psr-7 request-id

22/01 2016

dev-develop

dev-develop

Request Id middleware with PSR-7

  Sources   Download

The Requires

 

The Development Requires

middleware psr psr-7 request-id

22/01 2016

3.0.0

3.0.0.0

Request Id middleware with PSR-7

  Sources   Download

The Requires

 

The Development Requires

middleware psr psr-7 request-id

13/12 2015

2.1.0

2.1.0.0

Request Id middleware with PSR-7

  Sources   Download

The Requires

 

The Development Requires

middleware psr psr-7 request-id

09/12 2015

dev-feature/override-policy

dev-feature/override-policy

Request Id middleware with PSR-7

  Sources   Download

The Requires

 

The Development Requires

middleware psr psr-7 request-id

09/12 2015

dev-feature/codeclimate

dev-feature/codeclimate

Request Id middleware with PSR-7

  Sources   Download

The Requires

 

The Development Requires

middleware psr psr-7 request-id

11/11 2015

2.0.0

2.0.0.0

Request Id middleware with PSR-7

  Sources   Download

The Requires

 

The Development Requires

middleware psr psr-7 request-id

02/09 2015

1.0.0

1.0.0.0

Request Id middleware with PSR-7

  Sources   Download

The Requires

 

The Development Requires

middleware psr psr-7 request-id