PHPackages                             milpa/events - 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. [Framework](/categories/framework)
4. /
5. milpa/events

ActiveLibrary[Framework](/categories/framework)

milpa/events
============

String-named event dispatch for the Milpa PHP framework: dot-segment wildcard subscriptions, priorities, listener error isolation, and a pluggable async (queue) seam.

v0.2.0(2d ago)0124↓31.4%3Apache-2.0PHP &gt;=8.3

Since Jul 7Compare

[ Source](https://github.com/getmilpa/events)[ Packagist](https://packagist.org/packages/milpa/events)[ RSS](/packages/milpa-events/feed)WikiDiscussions Synced today

READMEChangelog (3)Dependencies (6)Versions (4)Used By (3)

 [   ![Milpa](https://raw.githubusercontent.com/getmilpa/core/main/art/lockup/milpa-lockup-v-color-light.svg)  ](https://github.com/getmilpa)

Milpa Events
============

[](#milpa-events)

> The **reference event dispatcher** for the Milpa PHP framework, built on **`milpa/core`**. String-named events with dot-segment wildcard subscriptions (`user.*`), priority ordering, per-listener error isolation, and a pluggable async (queue) seam — the concrete implementation of the `MilpaEventDispatcherInterface` contract `milpa/core` defines.

[![CI](https://github.com/getmilpa/events/actions/workflows/ci.yml/badge.svg)](https://github.com/getmilpa/events/actions/workflows/ci.yml)[![Packagist](https://camo.githubusercontent.com/c3190b3ec5b120fef9e2c8d79588a0b2ae0f76bf3abcafb31f80378b2713625d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d696c70612f6576656e74732e737667)](https://packagist.org/packages/milpa/events)[![PHP](https://camo.githubusercontent.com/ca03f11ea27dac4dedc8ad56a7bdfc4a9ff5feb825055f9d2983616115076607/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d254532253839254135253230382e332d3737376262342e737667)](https://www.php.net/)[![License](https://camo.githubusercontent.com/798509b4df525f56802b56f8096862487f08023e3d7561c68656f8dab10d0d6e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4170616368652d2d322e302d626c75652e737667)](LICENSE)[![Docs](https://camo.githubusercontent.com/c6dc6a3411e15b0ac7cc4583e8e6a8144181caedb82f5d98753353decda06d77/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63732d4150492532307265666572656e63652d626c75652e737667)](https://getmilpa.github.io/events/)

`milpa/events` is where `milpa/core`'s event-dispatch seam becomes a working engine. `Milpa\Interfaces\Event\MilpaEventDispatcherInterface` is a contract defined in core; this package is the concrete `EventDispatcher` — plugins publish and subscribe to string-named events (`'user.created'`, `'order.shipped'`) without depending on each other directly. **No Doctrine, no HTTP kernel, no concrete queue** — the async seam is a plain callable you wire in; the queue itself lives in your host application.

Install
-------

[](#install)

```
composer require milpa/events
```

Quick example
-------------

[](#quick-example)

Subscribe by exact name or by a dot-segment wildcard, dispatch, and let priority decide the call order — higher priority runs first:

```
use Milpa\Eventing\EventDispatcher;
use Psr\Log\NullLogger;

$dispatcher = new EventDispatcher(new NullLogger());

$dispatcher->subscribe('user.*', function (string $event, array $payload): void {
    // catches every one-segment event under `user.` — user.created, user.updated, ...
});

$dispatcher->subscribe('user.created', function (string $event, array $payload): void {
    // runs before the wildcard handler above: higher priority
}, priority: 10);

$dispatcher->dispatch('user.created', ['id' => 42]);

$dispatcher->hasSubscribers('user.created'); // true
$dispatcher->hasSubscribers('order.created'); // false — no exact or wildcard match
```

A handler that throws is logged and does **not** stop the remaining handlers — one bad listener never aborts a dispatch:

```
$dispatcher->subscribe('order.placed', fn () => throw new \RuntimeException('boom'));
$dispatcher->subscribe('order.placed', fn () => /* still runs */ null);

$dispatcher->dispatch('order.placed'); // both handlers ran; the exception was logged, not thrown
```

Wildcard grammar
----------------

[](#wildcard-grammar)

Event names are dot-separated segments; `*` matches exactly **one** segment — it never spans a `.`. Matching is case-sensitive and anchored (the whole name must match):

PatternMatchesDoes not match`user.*``user.created`, `user.deleted``user.profile.updated` (two segments after `user.`)`*.created``user.created`, `order.created``user.createdX` (anchored, not a substring match)`*``boot`, `ready` (single-segment names)`user.created` (dotted)Async: a seam, not an implementation
------------------------------------

[](#async-a-seam-not-an-implementation)

`dispatch($event, $payload, async: true)` requests deferred execution. **This package ships no queue** — you wire one in with `setAsyncDispatcher()`:

```
$dispatcher->setAsyncDispatcher(function (string $event, array $payload): void {
    // hand off to your queue (Symfony Messenger, a Doctrine-backed job table, ...)
});

$dispatcher->dispatch('order.placed', ['id' => 1], async: true); // -> queue, not inline
```

Without a dispatcher wired, `async: true` **degrades to synchronous dispatch** (subscribers run inline, in the same call) rather than silently dropping the event — a conformant fallback per the interface's documented `$async` contract, not a bug. Both branches are covered in `tests/EventDispatcherTest.php`.

Why the namespace is `Milpa\Eventing`
-------------------------------------

[](#why-the-namespace-is-milpaeventing)

`milpa/core` already owns `Milpa\Events\` for its event *objects*(`VerificationRequestedEvent` and friends, under `src/Events/`). A package literally named `milpa/events` colliding with that namespace would either clash or force an awkward split. `Milpa\EventDispatcher\EventDispatcher` was the other candidate and stutters. `Milpa\Eventing`avoids both: no collision, no stutter, and it names the *mechanism* (dispatch, subscribe, wildcards, priority) distinctly from `Milpa\Events`, which names the *event objects* — the two packages' responsibilities stay visibly distinct. This follows the family-wide rule: namespace semantically correct beats cosmetic symmetry with the package name.

What lives where
----------------

[](#what-lives-where)

LayerPackageOwnsContracts`milpa/core``MilpaEventDispatcherInterface`, `EventSubscriberInterface` — the seam, not the engine.**Dispatcher****`milpa/events`** (this package)The concrete `EventDispatcher`: exact + wildcard subscriber matching, priority ordering, listener error isolation, and the async seam.Your appyour host / pluginsThe queue `setAsyncDispatcher()` hands events to, and any PSR-3 logger you pass in.Requirements
------------

[](#requirements)

- PHP **≥ 8.3**
- [`milpa/core`](https://packagist.org/packages/milpa/core) **^0.3**
- [`psr/log`](https://packagist.org/packages/psr/log) **^3**

Documentation
-------------

[](#documentation)

**Full API reference: [getmilpa.github.io/events](https://getmilpa.github.io/events/)** — generated straight from the source DocBlocks and dressed with the Milpa design system.

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

[](#contributing)

Contributions are welcome — see [CONTRIBUTING.md](CONTRIBUTING.md). Please report security issues via [SECURITY.md](SECURITY.md), and note that this project follows a [Code of Conduct](CODE_OF_CONDUCT.md).

License
-------

[](#license)

[Apache-2.0](LICENSE) © TeamX Agency.

---

Milpa is designed, built, and maintained by **[TeamX Agency](https://teamx.agency/?utm_source=github&utm_medium=readme&utm_campaign=milpa&utm_content=events)**.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance99

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

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 ~0 days

Total

3

Last Release

2d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1993784?v=4)[rodrigomx](/maintainers/rodrigomx)[@rodrigomx](https://github.com/rodrigomx)

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/milpa-events/health.svg)

```
[![Health](https://phpackages.com/badges/milpa-events/health.svg)](https://phpackages.com/packages/milpa-events)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M20.3k](/packages/laravel-framework)[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21866.0M1.8k](/packages/drupal-core)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M423](/packages/drupal-core-recommended)

PHPackages © 2026

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