PHPackages                             andrewdyer/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. andrewdyer/event-dispatcher

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

andrewdyer/event-dispatcher
===========================

A simple event dispatcher that you can fit into the framework of your choice

1.0.0(1y ago)11MITPHPPHP ^8.3CI passing

Since Apr 24Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/andrewdyer/event-dispatcher)[ Packagist](https://packagist.org/packages/andrewdyer/event-dispatcher)[ RSS](/packages/andrewdyer-event-dispatcher/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

[![Event Dispatcher](https://camo.githubusercontent.com/471b6c04b3cdad0a5f28dd5bb56f0ce830a4f14fc4cd4c1b867ee3e74ccc6b82/687474703a2f2f7075626c69632d6173736574732e616e64726577647965722e726f636b732f696d616765732f636f766572732f6576656e742d646973706174636865722e706e67)](https://camo.githubusercontent.com/471b6c04b3cdad0a5f28dd5bb56f0ce830a4f14fc4cd4c1b867ee3e74ccc6b82/687474703a2f2f7075626c69632d6173736574732e616e64726577647965722e726f636b732f696d616765732f636f766572732f6576656e742d646973706174636865722e706e67)

Event Dispatcher
================

[](#event-dispatcher)

A simple event dispatcher that you can fit into the framework of your choice.

⚖️ License
----------

[](#️-license)

Licensed under the [MIT license](https://opensource.org/licenses/MIT) and is free for private or commercial projects.

✨ Introduction
--------------

[](#-introduction)

Event Dispatcher is a lightweight, framework-agnostic library for implementing the observer pattern in PHP. It enables you to define events and attach listeners that react when those events are triggered - keeping your code clean, modular, and easy to extend.

📋 Prerequisites
---------------

[](#-prerequisites)

Before you begin, ensure you have met the following requirements:

- **PHP**: Version 8.3 or higher.
- **[Composer](https://getcomposer.org)**: A dependency manager for PHP, used to install packages and autoload your code.

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

[](#-installation)

Install the package via Composer:

```
composer require andrewdyer/event-dispatcher
```

🚀 Getting Started
-----------------

[](#-getting-started)

### 1. Define Your Events

[](#1-define-your-events)

Create a class that implements `AndrewDyer\EventDispatcher\Events\EventInterface` (or extend `AbstractEvent`).

By default, the event name is the class name, but you can override it:

```
namespace App\Events;

use AndrewDyer\EventDispatcher\Events\AbstractEvent;

class UserRegistered extends AbstractEvent
{
    public function getName(): string
    {
        return 'UserRegistered';
    }
}
```

### 2. Create Your Listeners

[](#2-create-your-listeners)

Listeners must implement `AndrewDyer\EventDispatcher\Listeners\ListenerInterface` (or extend `AbstractListener`).

```
namespace App\Listeners;

use AndrewDyer\EventDispatcher\Events\EventInterface;
use AndrewDyer\EventDispatcher\Listeners\AbstractListener;

class SendRegistrationEmail extends AbstractListener
{
    public function handle(EventInterface $event): void
    {
        // Send welcome email to user...
    }
}
```

📖 Usage
-------

[](#-usage)

### Initialize the Dispatcher

[](#initialize-the-dispatcher)

Create a new instance of the event dispatcher:

```
use AndrewDyer\EventDispatcher\EventDispatcher;

$dispatcher = new EventDispatcher();
```

### Register a Listener

[](#register-a-listener)

Attach a listener class to respond to a specific event:

```
use App\Listeners\SendRegistrationEmail;

$dispatcher->addListener('UserRegistered', new SendRegistrationEmail());
```

> 💡 **Tip**: You can register multiple listeners for the same event name, and they will be executed in the order they were added.

### Dispatch an Event

[](#dispatch-an-event)

Trigger the event and notify all registered listeners:

```
use App\Events\UserRegistered;

$dispatcher->dispatch(new UserRegistered());
```

🤝 Contributing
--------------

[](#-contributing)

Found a bug or want to improve this package? Feel free to open a pull request or submit an issue.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance59

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

Unknown

Total

1

Last Release

383d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/666597ea6e46748a89fe8764d1a45b4d0da97daf1bb1e9770ea34ae41f706d08?d=identicon)[andrewdyer](/maintainers/andrewdyer)

---

Top Contributors

[![andrewdyer](https://avatars.githubusercontent.com/u/8114523?v=4)](https://github.com/andrewdyer "andrewdyer (19 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

PHPackages © 2026

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