Correlation ID and PSR7 middleware to inject it
A Correlation ID, also known as a Transit ID, is a unique identifier value that is attached to requests and messages that allow reference to a particular transaction or event chain. The Correlation Pattern, which depends on the use of Correlation ID is a well documented Enterprise Integration Pattern.
The correlation ID is a singleton class that will always return the same ID for the current life-cycle of the request.
The middleware will automatically put the correlation ID into your request object as attribute and header value. By default both use the
$middleware = new CorrelationIDMiddleware( CorrelationID::toString() );
Since there is no standard for where this needs to be done, just add the correlation ID to your response where ever it suits your architecture or framework.
Licensed under the MIT license.
Copyright (c) Phauthentic / Florian Krämer