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

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

onoi/event-dispatcher
=====================

A minimalistic interface to relay generic events to registered listeners

1.1.0(7y ago)1570.3k↑76.6%3GPL-2.0-or-laterPHPPHP &gt;=5.3.2

Since Mar 25Pushed 7y ago1 watchersCompare

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

READMEChangelog (2)DependenciesVersions (3)Used By (3)

Event dispatcher
================

[](#event-dispatcher)

[![Build Status](https://camo.githubusercontent.com/f5dfcafe467b9bb6f16b440eab24b1da65e33573ba00a36dad766b3d519fc5d1/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6f6e6f692f6576656e742d646973706174636865722e7376673f6272616e63683d6d6173746572)](http://travis-ci.org/onoi/event-dispatcher)[![Code Coverage](https://camo.githubusercontent.com/20bf07201c8e777c8bd1a411705ad60a9e393ba4214f01cbf9ba6590fd5831ef/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f6e6f692f6576656e742d646973706174636865722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/onoi/event-dispatcher/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/08efcf757fa85159f7316c755f73ca4abeb5b11b573cf624e75c3960cf2e8210/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f6e6f692f6576656e742d646973706174636865722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/onoi/event-dispatcher/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/50005c4487c656e58ef96012d5def485de9ee1b7372ca114077ca721f54e7ad4/68747470733a2f2f706f7365722e707567782e6f72672f6f6e6f692f6576656e742d646973706174636865722f76657273696f6e2e706e67)](https://packagist.org/packages/onoi/event-dispatcher)[![Packagist download count](https://camo.githubusercontent.com/523b4d6f7f50ef020442f25fa3013ca824065e7b31d2cee3b737c39632df04f5/68747470733a2f2f706f7365722e707567782e6f72672f6f6e6f692f6576656e742d646973706174636865722f642f746f74616c2e706e67)](https://packagist.org/packages/onoi/event-dispatcher)

A minimalistic event dispatcher (observer) interface that was part of the [Semantic MediaWiki](https://github.com/SemanticMediaWiki/SemanticMediaWiki/) code base and is now being deployed as independent library.

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

[](#requirements)

PHP 5.3/HHVM 3.3 or later

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

[](#installation)

The recommended installation method for this library is by either adding the dependency to your [composer.json](https://getcomposer.org/).

```
{
	"require": {
		"onoi/event-dispatcher": "~1.0"
	}
}
```

Usage
-----

[](#usage)

```
class BarListener implements EventListener {

	public function execute( DispatchContext $dispatchContext = null ) {
		// Do something
	}

	public function isPropagationStopped() {
		return false;
	}
}
```

```
class ListenerCollectionRegistry implements EventListenerCollection {

	private $eventListenerCollection;

	public function __construct( EventListenerCollection $eventListenerCollection ) {
		$this->eventListenerCollection = $eventListenerCollection;
	}

	public function getCollection() {
		return $this->addToListenerCollection()->getCollection();
	}

	private function addToListenerCollection() {

		$this->eventListenerCollection->registerCallback( 'do.something', function() {
			// Do something
		} );

		$this->eventListenerCollection->registerListener( 'notify.bar', new BarListener() );

		return $this->eventListenerCollection;
	}
}
```

```
$eventDispatcherFactory = new EventDispatcherFactory();

$listenerCollectionRegistry = new ListenerCollectionRegistry(
	$eventDispatcherFactory->newGenericEventListenerCollection()
);

$eventDispatcher = $eventDispatcherFactory->newGenericEventDispatcher();
$eventDispatcher->addListenerCollection( $listenerCollectionRegistry );

class Foo {

	use EventDispatcherAwareTrait;

	public function doSomething() {

		// No context
		$this->eventDispatcher->dispatch( 'do.something' );

		$dispatchContext = new DispatchContext();
		$dispatchContext->set( 'dosomethingelse', new \stdClass );

		// Using `DispatchContext`
		$this->eventDispatcher->dispatch( 'notify.bar', $dispatchContext );

		// Using an array as context which is later converted into
		// a `DispatchContext`
		$this->eventDispatcher->dispatch( 'notify.foo', [ 'Bar' => 123 ] );
	}
}

$instance = new Foo();
$instance->setEventDispatcher( $eventDispatcher );
$instance->doSomething();
```

Contribution and support
------------------------

[](#contribution-and-support)

If you want to contribute work to the project please subscribe to the developers mailing list and have a look at the [contribution guidelinee](/CONTRIBUTING.md). A list of people who have made contributions in the past can be found [here](https://github.com/onoi/event-dispatcher/graphs/contributors).

- [File an issue](https://github.com/onoi/event-dispatcher/issues)
- [Submit a pull request](https://github.com/onoi/event-dispatcher/pulls)

### Tests

[](#tests)

The library provides unit tests that covers the core-functionality normally run by the [continues integration platform](https://travis-ci.org/onoi/event-dispatcher). Tests can also be executed manually using the PHPUnit configuration file found in the root directory.

### Release notes

[](#release-notes)

- 1.1.0 (2019-01-27)
    - Allowed `EventDispatcher::dispatch` to take an array as context object
    - Added the `EventNotDispatchableException` and `Subscriber` interface
    - Added the `EventDispatcherAwareTrait` class

- 1.0.0 initial release (2015-03-25)

License
-------

[](#license)

[GNU General Public License 2.0 or later](https://www.gnu.org/copyleft/gpl.html).

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.4% 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 ~1403 days

Total

2

Last Release

2669d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/372f9bc1233d5518b9522cb681210a8de2765a3a9bbde20138f6ad5332a411ca?d=identicon)[mwjames](/maintainers/mwjames)

![](https://www.gravatar.com/avatar/511b3dbc1a73ad7b69118e540b16c8bcc2ac5f923022b94aa61a8d71af612f9c?d=identicon)[onoi](/maintainers/onoi)

---

Top Contributors

[![mwjames](https://avatars.githubusercontent.com/u/1245473?v=4)](https://github.com/mwjames "mwjames (17 commits)")[![kghbln](https://avatars.githubusercontent.com/u/1104078?v=4)](https://github.com/kghbln "kghbln (1 commits)")

---

Tags

eventslistener

### Embed Badge

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

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

###  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)[psr/event-dispatcher

Standard interfaces for event handling.

2.3k618.8M865](/packages/psr-event-dispatcher)[league/event

Event package

1.6k141.6M184](/packages/league-event)[laminas/laminas-eventmanager

Trigger and listen to events within a PHP application

1.0k69.8M225](/packages/laminas-laminas-eventmanager)[simshaun/recurr

PHP library for working with recurrence rules

1.6k15.7M40](/packages/simshaun-recurr)[chelout/laravel-relationship-events

Missing relationship events for Laravel

5252.3M17](/packages/chelout-laravel-relationship-events)

PHPackages © 2026

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