Skip to content

Commit

Permalink
Removing the hard dependency on ramsey/uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankraemer committed Mar 27, 2024
1 parent 839bd5c commit d1046eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
"require-dev": {
"phpunit/phpunit": "^10.0",
"phpstan/phpstan": "^1.10.0",
"ramsey/uuid": "^3.0 || ^4.0",
"squizlabs/php_codesniffer": "^3.6"
},
"suggest": {
"ramsey/uuid": "If you want to use this UUID generator for the correlation ID. It will be automatically used instead of built in UUID4v1 generator if it is available."
},
"license": "MIT",
"authors": [
{
Expand Down
16 changes: 12 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,43 @@
[![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/Phauthentic/correlation-id/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/Phauthentic/correlation-id/)
[![Code Quality](https://img.shields.io/scrutinizer/g/Phauthentic/correlation-id/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/Phauthentic/correlation-id/)

An implementation of a Correlation ID and a framework agnostic PSR 15-HTTP middlware.

> 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 value of a correlation ID](https://blog.rapid7.com/2016/12/23/the-value-of-correlation-ids/)
* [Identity Correlation on Wikipedia](https://en.wikipedia.org/wiki/Identity_correlation)

## Documentation

### Correlation ID
### The Correlation ID Value Object

The correlation ID is a singleton class that will always return the same ID for the current life-cycle of the request.

### Middleware
Calling `CorrelationID::toString()` will return a string and will return the same string for the whole live cycle of the application. You can compare a string to the Correlation ID by calling `CorrelationID::sameAs('your-string')`.

By default it uses its internal implementation to generate a UUID v4 as value of the Correlation ID. If you are using [ramsey/uuid](https://github.com/ramsey/uuid), it will use it automatically.

### PSR 15 HTTP Middleware

The middleware will automatically put the correlation ID into your request object as attribute and header value. By default both use the `CorrelationID` name.

```
```php
$middleware = new CorrelationIDMiddleware(
CorrelationID::toString()
);
```

### Response

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.
Since there is no standard for where this needs to be done, just add the correlation ID to your response where it suits your architecture or framework the best.

```php
$response->withHeader('CorrelationID', CorrelationId::toString());
```

For Symfony there is a [bundle](https://github.com/Phauthentic/correlation-id-symfony-bundle) available that will automatically make the Correlation ID available in the request and response object.

## Copyright & License

Licensed under the [MIT license](LICENSE.txt).
Expand Down

0 comments on commit d1046eb

Please sign in to comment.