ensi / initiator-propagation
initial event propagation
Package info
github.com/ensi-platform/php-initial-event-propagation
pkg:composer/ensi/initiator-propagation
Requires
- php: ^8.1
- ramsey/uuid: ^4.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.2
- pestphp/pest: ^1.22 || ^2.0 || ^3.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.11
- spaze/phpstan-disallowed-calls: ^2.15
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This package helps to propagate initial event data to other backend services Laravel Bridge
Installation
You can install the package via composer:
composer require ensi/initial-event-propagation
Version Compatibility
| Laravel IEP | PHP |
|---|---|
| ^0.1.0 | ^8.0 |
| ^0.2.0 | ^8.0 |
| ^0.3.0 | ^8.1 |
Basic usage
First of all you need to create initial event data and place it to holder:
use Ensi\InitialEventPropagation\InitialEventHolder; use Ensi\InitialEventPropagation\InitialEventDTO; InitialEventHolder::getInstance() ->setInitialEvent( InitialEventDTO::fromScratch( userId: "1", userType: "admin", app: "mobile-api-gateway", entrypoint: "/api/v1/users/{id}" ) );
If you are not in initial entrypoint context to need to get initial event from X-Initial-Event request header instead of creating it from scratch:
use Ensi\InitialEventPropagation\Config; use Ensi\InitialEventPropagation\InitialEventHolder; use Ensi\InitialEventPropagation\InitialEventDTO; InitialEventHolder::getInstance() ->setInitialEvent( InitialEventDTO::fromSerializedString($request->header(Config::REQUEST_HEADER)) );
Next, extract DTO from holder (InitialEventHolder::getInstance()->getInitialEvent()) and pass it to any futher outcomming requests (Guzzle, RabbitMQ, Kafka etc)
For example:
use Ensi\InitialEventPropagation\Config; use Ensi\InitialEventPropagation\InitialEventHolder; function some_middleware(callable $handler) { return function (RequestInterface $request, $options) use ($handler) { $inititiator = InitialEventHolder::getInstance()->getInitialEvent(); return $handler( $inititiator ? $request->withHeader(Config::REQUEST_HEADER, $inititiator->serialize()) : $request, $options ); }; }
Contributing
Please see CONTRIBUTING for details.
Testing
- composer install
- composer test
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
License
The MIT License (MIT). Please see License File for more information.