PHPackages                             ez-php/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. ez-php/events

ActiveLibrary[Framework](/categories/framework)

ez-php/events
=============

Event dispatcher module for the ez-php framework — lightweight publish/subscribe event system

1.11.1(1mo ago)0229↓90%2MITPHPPHP ^8.5CI passing

Since Mar 15Pushed 1mo agoCompare

[ Source](https://github.com/ez-php/events)[ Packagist](https://packagist.org/packages/ez-php/events)[ Docs](https://github.com/ez-php/events)[ RSS](/packages/ez-php-events/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (16)Versions (43)Used By (2)

ez-php/events
=============

[](#ez-phpevents)

Event dispatcher module for the [ez-php framework](https://github.com/ez-php/framework) — synchronous event bus with listener priority, wildcard patterns, propagation control, and async dispatch via queue.

[![CI](https://github.com/ez-php/events/actions/workflows/ci.yml/badge.svg)](https://github.com/ez-php/events/actions/workflows/ci.yml)

Requirements
------------

[](#requirements)

- PHP 8.5+
- ez-php/framework 0.\*

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

[](#installation)

```
composer require ez-php/events
```

Setup
-----

[](#setup)

Register the service provider:

```
$app->register(\EzPhp\Events\EventServiceProvider::class);
```

Usage
-----

[](#usage)

### Defining an event

[](#defining-an-event)

```
use EzPhp\Events\EventInterface;

class UserCreated implements EventInterface
{
    public function __construct(public readonly int $userId) {}
}
```

### Listening and dispatching

[](#listening-and-dispatching)

```
use EzPhp\Events\Event;

// Register a closure listener
Event::listen(UserCreated::class, function (UserCreated $event): void {
    // send welcome email
});

// Register a class-based listener
Event::listen(UserCreated::class, new SendWelcomeEmail());

// Dispatch
Event::dispatch(new UserCreated(42));
```

### Listener priority

[](#listener-priority)

Higher priority fires first. Listeners with equal priority fire in registration order.

```
Event::listen(UserCreated::class, new LogUserCreation(), priority: 10);
Event::listen(UserCreated::class, new SendWelcomeEmail(), priority: 5);
// LogUserCreation fires before SendWelcomeEmail
```

### Wildcard patterns

[](#wildcard-patterns)

Use `*` and `?` (fnmatch-style) to listen to multiple event classes at once:

```
Event::listen('App\Events\Order*', function (EventInterface $event): void {
    // fires for OrderPlaced, OrderShipped, OrderDelivered, ...
});
```

### Stopping propagation

[](#stopping-propagation)

Implement `StoppableEventInterface` to stop further listeners mid-dispatch:

```
use EzPhp\Events\StoppableEventInterface;

class UserCreated implements StoppableEventInterface
{
    private bool $stopped = false;

    public function isPropagationStopped(): bool { return $this->stopped; }
    public function stopPropagation(): void { $this->stopped = true; }
}
```

A Closure listener can also stop propagation by returning `false`.

### Async dispatch

[](#async-dispatch)

Pass `async: true` to push the event onto a queue instead of running listeners immediately (requires a `QueueInterface` configured on the dispatcher):

```
Event::dispatch(new UserCreated(42), async: true);
```

When no queue is configured, `async: true` falls through to synchronous dispatch.

Config-based listener registration
----------------------------------

[](#config-based-listener-registration)

Declare listeners in `config/events.php` — `EventServiceProvider` registers them automatically during `boot()`:

```
return [
    'listeners' => [
        UserCreated::class => [
            SendWelcomeEmail::class,
            LogUserCreation::class,
        ],
    ],
];
```

Each listener class is resolved through the container (supports autowiring). Additional listeners can still be registered imperatively in any service provider that boots after `EventServiceProvider`:

```
Event::listen(OrderPlaced::class, new SendOrderConfirmation());
```

Class-based listeners
---------------------

[](#class-based-listeners)

```
use EzPhp\Events\ListenerInterface;

class SendWelcomeEmail implements ListenerInterface
{
    public function handle(EventInterface $event): void
    {
        assert($event instanceof UserCreated);
        // send the email
    }
}
```

Classes
-------

[](#classes)

ClassDescription`EventInterface`Marker interface all dispatchable events must implement`ListenerInterface`Contract for class-based listeners: `handle(EventInterface): void``StoppableEventInterface`Extends `EventInterface`; events can call `stopPropagation()` to halt the dispatch chain`EventDispatcher`Synchronous bus with priority ordering, wildcard matching, propagation control, and async queue support`Event`Static façade backed by a managed `EventDispatcher` singleton`AsyncEventJob``JobInterface` implementation that wraps an event for deferred queue-based dispatch`EventServiceProvider`Binds `EventDispatcher`, wires static façade, auto-registers `config/events.php` listenersLicense
-------

[](#license)

MIT — [Andreas Uretschnig](mailto:andreas.uretschnig@gmail.com)

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance91

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 90.6% 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 ~1 days

Total

42

Last Release

44d ago

Major Versions

0.9.3 → 1.0.02026-03-24

### Community

Maintainers

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

---

Top Contributors

[![AU9500](https://avatars.githubusercontent.com/u/122030400?v=4)](https://github.com/AU9500 "AU9500 (126 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (13 commits)")

---

Tags

phpframeworkeventsevent dispatcherpub-subez-php

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

PHPackages © 2026

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