PHPackages                             ensi/laravel-initial-event-propagation - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ensi/laravel-initial-event-propagation

ActiveLibrary

ensi/laravel-initial-event-propagation
======================================

Laravel initial event propagation

0.3.4(7mo ago)287.4k↓23.4%2[1 PRs](https://github.com/ensi-platform/laravel-initial-event-propagation/pulls)MITPHPPHP ^8.1CI passing

Since Nov 18Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/ensi-platform/laravel-initial-event-propagation)[ Packagist](https://packagist.org/packages/ensi/laravel-initial-event-propagation)[ RSS](/packages/ensi-laravel-initial-event-propagation/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (19)Used By (0)

Laravel Initial Event Propagation
=================================

[](#laravel-initial-event-propagation)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a9abf270081b490f0847a7688a21d730599ee24bae8eed25d99279d44f5a1f2f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656e73692f6c61726176656c2d696e697469616c2d6576656e742d70726f7061676174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ensi/laravel-initial-event-propagation)[![Tests](https://github.com/ensi-platform/laravel-initial-event-propagation/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/ensi-platform/laravel-initial-event-propagation/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/e0b17165eac00849e5118319f6ac2eecad3ee5425ddc61be52feabc9300184c9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656e73692f6c61726176656c2d696e697469616c2d6576656e742d70726f7061676174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ensi/laravel-initial-event-propagation)

Provides a bunch of ready-to use middleware to integrate [ensi/initial-event-propagation](https://github.com/ensi-platform/php-initial-event-propagation/) in Laravel application. You are free to replace any of them with your own implementations.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require ensi/laravel-initial-event-propagation
```

Publish config file like this:

```
php artisan vendor:publish --provider="Ensi\LaravelInitialEventPropagation\LaravelInitialEventPropagationServiceProvider"
```

Version Compatibility
---------------------

[](#version-compatibility)

Laravel IEPLaravelPHP^0.1.0^8.x^8.0^0.2.0^8.x^8.0^0.2.5^8.x || ^9.x^8.0^0.2.6^8.x || ^9.x^8.1^0.2.9^8.x || ^9.x || ^10.x^8.1^0.2.11^8.x || ^9.x || ^10.x || ^11.x^8.1^0.3.0^9.x || ^10.x || ^11.x^8.1Basic Usage
-----------

[](#basic-usage)

```
$holder = resolve(InitialEventHolder::class);
var_dump($holder->getInitialEvent());
$holder->setInitialEvent(new InitialEventDTO(...));
```

You must always resolve InitialEventHolder from the service container instead of `InitialEventHolder::getInstance`. This is made forLaravel Octane compatibility.

### HTTP Requests

[](#http-requests)

#### Setting initial event

[](#setting-initial-event)

You typically create a new initial event when you receive a HTTP request coming from a client you do not own. E.g in an API Gateway.
There is a built-in `Ensi\LaravelInitialEventPropagation\SetInitialEventHttpMiddleware` for that.
It creates an `InitialEventDTO` and places it to the `InitialEventHolder` singleton.

- `userId` and `entrypoint` are set from request.
- `app` is set according to config options.
- `userType` is set from the package config. `userType` is empty for a not authenticated user.
- `correlationId` and `timestamp` are set from request headers according to config options or generated from scratch.
- `realUserId`, `realUserType` and `misc` are left empty strings.

Be sure to add the midlleware AFTER Laravel middleware that sets authenticated user.
In practice it likely means that you have to place the middleare at the very bottom of `middlewareGroups` in `app/Http/Kernel`

#### Parsing incoming initial event

[](#parsing-incoming-initial-event)

Add `Ensi\LaravelInitialEventPropagation\ParseInitialEventHeaderMiddleware` to `app/Http/Kernel` middleware property.
This middleware parses `X-Initial-Event` HTTP header, deserializes it into `InitialEventDTO` object and places it to the `InitialEventHolder` singleton.

#### Propagating initial event to outcomming HTTP request

[](#propagating-initial-event-to-outcomming-http-request)

The package provides a `Ensi\LaravelInitialEventPropagation\PropagateInitialEventLaravelGuzzleMiddleware` Guzzle Middleware that converts ` resolve(InitialEventHolder::class)->getInitialEvent()` back to `X-Initial-Event` header and sets this header for all outcomming guzzle request.

You can add it to your guzzle stack like this:

```
$handlerStack = new HandlerStack(Utils::chooseHandler());
$handlerStack->push(new PropagateInitialEventLaravelGuzzleMiddleware());
```

### CLI

[](#cli)

#### Artisan Commands

[](#artisan-commands)

There is a custom artisan `Ensi\LaravelInitialEventPropagation\SetInitialEventArtisanMiddleware` that sets new initial event in every artisan command that you run. You can add it to the `app\Console\Kernel` like that:

```
public function bootstrap()
{
    parent::bootstrap();
    (new SetInitialEventArtisanMiddleware())->handle();
}
```

This middleware sets artisan command name (including argument, excluding options) as `$initialEventDTO->entrypoint`.
If your custom artisan command makes guzzle HTTP requests to other apps the `PropagateInitialEventGuzzleMiddleware` uses this initial event.
This middleware also works fine for [Laravel Task Scheduling](https://laravel.com/docs/latest/scheduling).

#### Queue Jobs

[](#queue-jobs)

You typically want to persist initial event between incoming HTTP request and queued job.
The package can help you here aswell. Unfortunately you need to touch a given job:

```
use Ensi\LaravelInitialEventPropagation\Job;

// Extend the job from package
class TestJob extends Job implements ShouldQueue
{
    public function __construct(protected Customer $customer)
    {
        // Do not forget to call parent constuctor
        parent::__construct();
    }

    public function handle()
    {
        // InitialEvent is automatically persisted to InitialEventHolder via job middleware in parent class,
        // You do not need to persist it manually
    }
}
```

#### Laravel Queable Actions

[](#laravel-queable-actions)

If you use [spatie/laravel-queueable-action](https://github.com/spatie/laravel-queueable-action) package to dispatch actions instead of jobs you do not need to mess with every job separately.

Just publish `laravel-queueable-action` config and set the special Job class there:

```
'job_class' => \Ensi\LaravelInitialEventPropagation\ActionJob::class,
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

### Testing

[](#testing)

1. composer install
2. composer test

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](.github/SECURITY.md) on how to report security vulnerabilities.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance65

Regular maintenance activity

Popularity35

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~84 days

Recently: every ~119 days

Total

18

Last Release

215d ago

PHP version history (2 changes)0.1.0PHP ^8.0

0.2.6PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8089373?v=4)[Наталия](/maintainers/MsNatali)[@MsNatali](https://github.com/MsNatali)

![](https://avatars.githubusercontent.com/u/7352966?v=4)[Andrey](/maintainers/dimionx)[@DimionX](https://github.com/DimionX)

---

Top Contributors

[![MsNatali](https://avatars.githubusercontent.com/u/8089373?v=4)](https://github.com/MsNatali "MsNatali (7 commits)")[![arrilot](https://avatars.githubusercontent.com/u/2826480?v=4)](https://github.com/arrilot "arrilot (3 commits)")[![valerialukinykh](https://avatars.githubusercontent.com/u/123940772?v=4)](https://github.com/valerialukinykh "valerialukinykh (2 commits)")[![DimionX](https://avatars.githubusercontent.com/u/7352966?v=4)](https://github.com/DimionX "DimionX (1 commits)")[![filippovano](https://avatars.githubusercontent.com/u/58265848?v=4)](https://github.com/filippovano "filippovano (1 commits)")[![C0rTeZ13](https://avatars.githubusercontent.com/u/120840631?v=4)](https://github.com/C0rTeZ13 "C0rTeZ13 (1 commits)")[![Timzan](https://avatars.githubusercontent.com/u/54365038?v=4)](https://github.com/Timzan "Timzan (1 commits)")[![bereza-evgenij](https://avatars.githubusercontent.com/u/7606944?v=4)](https://github.com/bereza-evgenij "bereza-evgenij (1 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ensi-laravel-initial-event-propagation/health.svg)

```
[![Health](https://phpackages.com/badges/ensi-laravel-initial-event-propagation/health.svg)](https://phpackages.com/packages/ensi-laravel-initial-event-propagation)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11120.2M21](/packages/anourvalar-eloquent-serialize)[namu/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

54324.5k](/packages/namu-wirechat)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
