PHPackages                             webware/mezzio-eventdispatcher - 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. webware/mezzio-eventdispatcher

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

webware/mezzio-eventdispatcher
==============================

League EventDispatcher

0.1.x-dev(4mo ago)2194[1 PRs](https://github.com/tyrsson/mezzio-eventdispatcher/pulls)BSD-3-ClausePHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Dec 27Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/tyrsson/mezzio-eventdispatcher)[ Packagist](https://packagist.org/packages/webware/mezzio-eventdispatcher)[ Docs](https://github.com/tyrsson/mezzio-eventdispatcher)[ RSS](/packages/webware-mezzio-eventdispatcher/feed)WikiDiscussions 0.1.x Synced 1mo ago

READMEChangelogDependencies (9)Versions (2)Used By (0)

Mezzio Event Dispatcher
=======================

[](#mezzio-event-dispatcher)

[![PHP Version](https://camo.githubusercontent.com/02f24bc538748cd7e67f50054c904c26747611bec040badf19a69fe2fdf8ded2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e32253230253743253230382e33253230253743253230382e34253230253743253230382e352d626c7565)](https://www.php.net/)[![License](https://camo.githubusercontent.com/e32287373926ec416e0928698ca4471080dc41437461969806bcfe2df245e480/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4253442d2d332d2d436c617573652d677265656e)](LICENSE)

A PSR-14 Event Dispatcher library for Mezzio/Laminas applications, providing seamless integration between [League Event](https://event.thephpleague.com/) and Laminas ServiceManager.

Features
--------

[](#features)

- ✅ **PSR-14 Compliant** - Full PSR-14 Event Dispatcher implementation
- ✅ **Laminas Integration** - Native ServiceManager/Dependency Injection support
- ✅ **Configuration-Based** - Register listeners and subscribers via configuration arrays
- ✅ **Immutable Events** - Type-safe, immutable event objects with fluent API
- ✅ **Priority Support** - Control listener execution order with priority levels
- ✅ **Type Safe** - PHP 8.2+ with strict types, readonly classes, and comprehensive PHPStan Level 10 coverage
- ✅ **Fully Tested** - 91 tests with comprehensive unit and integration coverage

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

[](#requirements)

- PHP 8.2, 8.3, 8.4, or 8.5
- [league/event](https://packagist.org/packages/league/event) ^3.0
- PSR-11 Container implementation (e.g., Laminas ServiceManager)

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

[](#installation)

```
composer require webware/mezzio-eventdispatcher
```

Quick Start
-----------

[](#quick-start)

### 1. Register the ConfigProvider

[](#1-register-the-configprovider)

Add the configuration provider to your application:

```
// config/config.php
use Webware\Event\ConfigProvider;

$aggregator = new ConfigAggregator([
    ConfigProvider::class,
    // ... other config providers
]);

return $aggregator->getMergedConfig();
```

### 2. Create an Event

[](#2-create-an-event)

```
use Webware\Event\ImmutableEvent;

// Immutable event (recommended for most use cases)
$event = new ImmutableEvent('user.created', $user, ['timestamp' => time()]);

// OR use mutable event when needed
use Webware\Event\MutableEvent;
$event = new MutableEvent('user.created', $user, ['timestamp' => time()]);
```

### 3. Create a Listener

[](#3-create-a-listener)

```
use Webware\Event\EventInterface;
use Webware\Event\ListenerInterface;

class UserCreatedListener implements ListenerInterface
{
    public function __invoke(EventInterface $event): void
    {
        $user = $event->getTarget();
        $params = $event->getParams();

        // Handle the event...
    }
}
```

### 4. Register Listener in Configuration

[](#4-register-listener-in-configuration)

```
// config/autoload/events.global.php
use Webware\Event\ConfigKey;
use Webware\Event\ListenerPriority;

return [
    ConfigKey::Listeners->value => [
        [
            'event' => 'user.created',
            'listener' => UserCreatedListener::class,
            'priority' => ListenerPriority::Normal->value,
        ],
    ],
    'dependencies' => [
        'factories' => [
            UserCreatedListener::class => YourListenerFactory::class,
        ],
    ],
];
```

### 5. Dispatch Events

[](#5-dispatch-events)

```
use Psr\EventDispatcher\EventDispatcherInterface;
use Webware\Event\ImmutableEvent;

class UserService
{
    public function __construct(
        private EventDispatcherInterface $dispatcher
    ) {}

    public function createUser(array $data): User
    {
        $user = new User($data);

        // Dispatch immutable event
        $event = new ImmutableEvent('user.created', $user);
        $this->dispatcher->dispatch($event);

        return $user;
    }
}
```

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

[](#documentation)

Comprehensive documentation is available in the [docs/](docs/) directory:

- **[Installation Guide](docs/installation.md)** - Detailed installation and setup instructions
- **[Basic Usage](docs/basic-usage.md)** - Getting started with events, listeners, and dispatching
- **[Configuration](docs/configuration.md)** - Configuration options and best practices
- **[Events](docs/events.md)** - Creating and working with events
- **[Event Types](docs/event-types.md)** - Understanding immutable vs mutable events
- **[Listeners](docs/listeners.md)** - Creating and registering event listeners
- **[Subscribers](docs/subscribers.md)** - Using listener subscribers for complex event handling
- **[Priorities](docs/priorities.md)** - Managing listener execution order
- **[Advanced Usage](docs/advanced-usage.md)** - Advanced patterns and techniques
- **[API Reference](docs/api-reference.md)** - Complete API documentation
- **[Testing](docs/testing.md)** - Testing your events and listeners

Example
-------

[](#example)

A complete example demonstrating all features:

```
use Psr\EventDispatcher\EventDispatcherInterface;
use Webware\Event\ImmutableEvent;

// In your service
class OrderService
{
    public function __construct(
        private EventDispatcherInterface $dispatcher
    ) {}

    public function placeOrder(Order $order): void
    {
        // Process order...
        $order->setStatus('completed');

        // Dispatch immutable event with context
        $event = new ImmutableEvent(
            name: 'order.completed',
            target: $order,
            params: [
                'user_id' => $order->getUserId(),
                'total' => $order->getTotal(),
                'timestamp' => time(),
            ]
        );

        $this->dispatcher->dispatch($event);
    }
}

// Listener 1: Send confirmation email
class OrderEmailListener implements ListenerInterface
{
    public function __invoke(EventInterface $event): void
    {
        $order = $event->getTarget();
        $this->emailService->sendOrderConfirmation($order);
    }
}

// Listener 2: Update inventory
class OrderInventoryListener implements ListenerInterface
{
    public function __invoke(EventInterface $event): void
    {
        $order = $event->getTarget();
        $this->inventoryService->decrementStock($order);
    }
}

// Configuration
return [
    ConfigKey::Listeners->value => [
        [
            'event' => 'order.completed',
            'listener' => OrderEmailListener::class,
            'priority' => ListenerPriority::Normal->value,
        ],
        [
            'event' => 'order.completed',
            'listener' => OrderInventoryListener::class,
            'priority' => ListenerPriority::High->value, // Runs first
        ],
    ],
];
```

Testing
-------

[](#testing)

This library includes comprehensive test suites:

```
# Run unit tests
composer test

# Run integration tests
composer test-integration

# Run all tests with coverage
composer test-coverage

# Run all quality checks (CS, PHPStan, tests)
composer check
```

Code Quality
------------

[](#code-quality)

- **PHPStan Level 10** - Maximum static analysis strictness
- **Laminas Coding Standard** - PSR-12 compliant with additional quality rules
- **100% Type Coverage** - Strict types and comprehensive type hints
- **Comprehensive Tests** - 91 tests covering all functionality

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

[](#contributing)

Contributions are welcome! Please ensure:

1. All tests pass: `composer check`
2. Code follows Laminas Coding Standard: `composer cs-check`
3. PHPStan Level 10 passes: `composer static-analysis`
4. New features include tests and documentation

License
-------

[](#license)

This project is licensed under the BSD-3-Clause License - see the [LICENSE](LICENSE) file for details.

Credits
-------

[](#credits)

- Built on [League Event](https://event.thephpleague.com/) by [The PHP League](https://thephpleague.com/)
- Designed for [Mezzio](https://docs.mezzio.dev/) and [Laminas](https://getlaminas.org/) applications

Support
-------

[](#support)

- **Issues**: [GitHub Issues](https://github.com/tyrsson/mezzio-eventdispatcher/issues)
- **Source**: [GitHub Repository](https://github.com/tyrsson/mezzio-eventdispatcher)

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance78

Regular maintenance activity

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

134d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4d6eed33e61a99f1147789696252f4523130b5035a19eb07e034a7407fd44548?d=identicon)[tyrsson](/maintainers/tyrsson)

---

Top Contributors

[![tyrsson](https://avatars.githubusercontent.com/u/1237487?v=4)](https://github.com/tyrsson "tyrsson (34 commits)")

---

Tags

event dispatchermezziocommand buspsr14cmdbusmezzio events

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/webware-mezzio-eventdispatcher/health.svg)

```
[![Health](https://phpackages.com/badges/webware-mezzio-eventdispatcher/health.svg)](https://phpackages.com/packages/webware-mezzio-eventdispatcher)
```

###  Alternatives

[doctrine/event-manager

The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.

6.1k501.1M115](/packages/doctrine-event-manager)[evenement/evenement

Événement is a very simple event dispatching library for PHP

1.3k147.0M318](/packages/evenement-evenement)[phly/phly-event-dispatcher

Experimental event dispatcher for PSR-14

26209.9k4](/packages/phly-phly-event-dispatcher)

PHPackages © 2026

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