PHPackages                             waffle-commons/event-dispatcher - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. waffle-commons/event-dispatcher

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

waffle-commons/event-dispatcher
===============================

Event Dispatcher component for Waffle framework.

0.1.0-beta4(1mo ago)117↓50%1MITPHPPHP ^8.5CI passing

Since May 3Pushed 1mo agoCompare

[ Source](https://github.com/waffle-commons/event-dispatcher)[ Packagist](https://packagist.org/packages/waffle-commons/event-dispatcher)[ RSS](/packages/waffle-commons-event-dispatcher/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (7)Dependencies (15)Versions (10)Used By (1)

[![Discord](https://camo.githubusercontent.com/b30f41baece56d71f7f496f7e39fd33a2a096221c66c648b350dd4fe14276c2e/68747470733a2f2f696d672e736869656c64732e696f2f646973636f72642f3735353238383030313539323033333339313f6c6f676f3d646973636f7264)](https://discord.gg/eKgywnfXr2)[![PHP Version Require](https://camo.githubusercontent.com/f257023dd4b739a92581e54cabb492ec47c4050e6bda873777a7ccacd8b6f197/687474703a2f2f706f7365722e707567782e6f72672f776166666c652d636f6d6d6f6e732f6576656e742d646973706174636865722f726571756972652f706870)](https://packagist.org/packages/waffle-commons/event-dispatcher)[![PHP CI](https://github.com/waffle-commons/event-dispatcher/actions/workflows/main.yml/badge.svg)](https://github.com/waffle-commons/event-dispatcher/actions/workflows/main.yml)[![codecov](https://camo.githubusercontent.com/17729b24051aeff7ffd31882adfc281b636384f784e40e5b3d94f40da575da5f/68747470733a2f2f636f6465636f762e696f2f67682f776166666c652d636f6d6d6f6e732f6576656e742d646973706174636865722f67726170682f62616467652e7376673f746f6b656e3d64373461633632612d373837322d343033352d386238622d626363336166313939316530)](https://codecov.io/gh/waffle-commons/event-dispatcher)[![Latest Stable Version](https://camo.githubusercontent.com/46f68064b677ef2859b92e53d1cfd90ba6d5aaa33d16eb128f06c24ed244d316/687474703a2f2f706f7365722e707567782e6f72672f776166666c652d636f6d6d6f6e732f6576656e742d646973706174636865722f76)](https://packagist.org/packages/waffle-commons/event-dispatcher)[![Latest Unstable Version](https://camo.githubusercontent.com/9aaa043159d3140df4afea31c892b659a812fa52757d4acc40f0ca39c5b34a6f/687474703a2f2f706f7365722e707567782e6f72672f776166666c652d636f6d6d6f6e732f6576656e742d646973706174636865722f762f756e737461626c65)](https://packagist.org/packages/waffle-commons/event-dispatcher)[![Total Downloads](https://camo.githubusercontent.com/e1b911fc2fadcaa702213925b965e94511f898a91b4d29dfab041341e0351262/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f776166666c652d636f6d6d6f6e732f6576656e742d646973706174636865722e737667)](https://packagist.org/packages/waffle-commons/event-dispatcher)[![Packagist License](https://camo.githubusercontent.com/376084cbf25af708cf9c6c514de44d949ef41cc9a20703c256d37913eeb32701/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f776166666c652d636f6d6d6f6e732f6576656e742d64697370617463686572)](https://github.com/waffle-commons/event-dispatcher/blob/main/LICENSE.md)

Waffle Event Dispatcher Component
=================================

[](#waffle-event-dispatcher-component)

> **Release:** `0.1.0-beta4` | [`CHANGELOG.md`](./CHANGELOG.md)**PSR Compliance:** PSR-14 (`Psr\EventDispatcher\EventDispatcherInterface`, `ListenerProviderInterface`, `StoppableEventInterface`)

A minimal, attribute-driven PSR-14 dispatcher. The dispatcher itself is `final readonly` and stateless; the listener provider stores the listener map and supports priority ordering and `#[AsEventListener]` attribute discovery.

📦 Installation
--------------

[](#-installation)

```
composer require waffle-commons/event-dispatcher
```

🧱 Surface
---------

[](#-surface)

ClassRole`Waffle\Commons\EventDispatcher\Dispatcher\EventDispatcher``final readonly` PSR-14 dispatcher. Walks listeners, respects `StoppableEventInterface`.`Waffle\Commons\EventDispatcher\Provider\ListenerProvider`Listener registry. Manual registration via `addListener()`, or attribute scanning via `register($object)`.`Waffle\Commons\EventDispatcher\Attribute\AsEventListener`PHP 8 attribute marking a class or method as a listener.`Waffle\Commons\EventDispatcher\Event\AbstractStoppableEvent`Convenience base implementing `StoppableEventInterface`.🚀 Manual registration
---------------------

[](#-manual-registration)

```
use Waffle\Commons\EventDispatcher\Dispatcher\EventDispatcher;
use Waffle\Commons\EventDispatcher\Provider\ListenerProvider;

$provider = new ListenerProvider();
$provider->addListener(UserRegistered::class, function (UserRegistered $event): void {
    // …
}, priority: 100); // higher priority = earlier

$dispatcher = new EventDispatcher($provider);
$event = $dispatcher->dispatch(new UserRegistered($userId));
```

🏷️ Attribute-driven registration (`#[AsEventListener]`)
-------------------------------------------------------

[](#️-attribute-driven-registration-aseventlistener)

The attribute is declared as:

```
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)]
final readonly class AsEventListener
{
    public function __construct(
        public ?string $event = null,
        public int $priority = 0,
    ) {}
}
```

### Method-level — event class resolved from the parameter type-hint

[](#method-level--event-class-resolved-from-the-parameter-type-hint)

```
final class AuditListener
{
    #[AsEventListener(priority: 50)]
    public function onUserRegistered(UserRegistered $event): void
    {
        // resolved automatically from the parameter type
    }
}

$provider->register(new AuditListener());
```

### Class-level — first public non-constructor method is the handler

[](#class-level--first-public-non-constructor-method-is-the-handler)

```
#[AsEventListener(event: UserRegistered::class, priority: 50)]
final class WelcomeMailer
{
    public function send(UserRegistered $event): void { /* … */ }
}

$provider->register(new WelcomeMailer());
```

🛑 Stoppable events
------------------

[](#-stoppable-events)

```
use Waffle\Commons\EventDispatcher\Event\AbstractStoppableEvent;

final class CancellableJob extends AbstractStoppableEvent
{
    public function __construct(public readonly string $jobId) {}
}

$provider->addListener(CancellableJob::class, function (CancellableJob $e): void {
    if ($shouldCancel) {
        $e->stopPropagation();
    }
});
```

The dispatcher honours `isPropagationStopped()` and breaks out of the listener loop.

🐘 PHP 8.5 features used
-----------------------

[](#-php-85-features-used)

- `final readonly class EventDispatcher` — the dispatcher itself is immutable.
- Constructor property promotion with explicit visibility on listeners.
- Typed properties + parameters throughout.
- Inheritance walks via native `get_parent_class()` (not reflection caches), so listener resolution against parent event types is `O(depth)` without warm-up cost.

🧭 Architectural boundary (`mago guard`)
---------------------------------------

[](#-architectural-boundary-mago-guard)

An active dependency **perimeter** is enforced on every CI run by `vendor/bin/mago guard` (bundled into `composer mago`; zero baselines). The rules live in [`mago.toml`](./mago.toml) under `[guard.perimeter]` — a forbidden `use` statement fails the build, not a reviewer.

Production code under `Waffle\Commons\EventDispatcher` may depend **only** on:

- `Waffle\Commons\EventDispatcher\**` — itself
- `Waffle\Commons\Contracts\**` — the shared contracts package, the **only** Waffle dependency permitted
- `Psr\**` — PSR interfaces (PSR-14)
- `@global` + `Psl\**` — PHP core and the PHP Standard Library

Test code under `WaffleTests\Commons\EventDispatcher` is unrestricted (`@all`). Structural rules are guarded too: interfaces must be named `*Interface`, `Exception\**` classes must end in `*Exception`, and any `Enum\**` namespace may hold only `enum` declarations.

Contract-first, component-agnostic by construction: components compose through `waffle-commons/contracts`, never directly through one another.

🧪 Testing
---------

[](#-testing)

```
docker exec -w /waffle-commons/event-dispatcher waffle-dev composer tests
```

📄 License
---------

[](#-license)

MIT — see [LICENSE.md](./LICENSE.md).

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance92

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Total

7

Last Release

41d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/34a7557a3fb23aaf788ca3892b9b7efdf96e753264bafd0599153c9e8a921316?d=identicon)[LesliePetrimaux](/maintainers/LesliePetrimaux)

---

Top Contributors

[![supa-chayajin](https://avatars.githubusercontent.com/u/695448?v=4)](https://github.com/supa-chayajin "supa-chayajin (46 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/waffle-commons-event-dispatcher/health.svg)

```
[![Health](https://phpackages.com/badges/waffle-commons-event-dispatcher/health.svg)](https://phpackages.com/packages/waffle-commons-event-dispatcher)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[symfony/event-dispatcher-contracts

Generic abstractions related to dispatching event

3.4k807.0M645](/packages/symfony-event-dispatcher-contracts)[deptrac/deptrac

Deptrac is a static code analysis tool that helps to enforce rules for dependencies between software layers.

3.0k8.8M207](/packages/deptrac-deptrac)[phpro/soap-client

A general purpose SoapClient library

8896.1M54](/packages/phpro-soap-client)[mcp/sdk

Model Context Protocol SDK for Client and Server applications in PHP

1.5k1.5M107](/packages/mcp-sdk)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

326123.0k1](/packages/cognesy-instructor-php)

PHPackages © 2026

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