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

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

gandung/event-dispatcher
========================

A simple event dispatcher library written in PHP

v1.0.0(8y ago)061BSD-3-ClausePHP

Since Sep 5Pushed 8y ago1 watchersCompare

[ Source](https://github.com/plvhx/event-dispatcher)[ Packagist](https://packagist.org/packages/gandung/event-dispatcher)[ RSS](/packages/gandung-event-dispatcher/feed)WikiDiscussions master Synced today

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

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

[](#event-dispatcher)

[![Minimum PHP Version](https://camo.githubusercontent.com/86e7d829a466cacd5658a22073e27d49d39dac72cc18216ac4963ed5463c5bbc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230352e362d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://php.net/)[![Build status](https://camo.githubusercontent.com/437a2616d7fa849c835755904eba6c25e219f65dd1dab68a8b66367e8cb66a70/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f78326c70736c63746535306b716a67673f7376673d74727565)](https://ci.appveyor.com/project/plvhx/event-dispatcher)[![SensioLabsInsight](https://camo.githubusercontent.com/7ac4d6edb0e63fa3a0a465b4f9ed112032d937d709cf2069bc0a4921dab9cd20/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f63373063643862612d643965662d343064312d383136382d6630396164386532643566362f6d696e692e706e67)](https://insight.sensiolabs.com/projects/c70cd8ba-d9ef-40d1-8168-f09ad8e2d5f6)

This is a simple library for managing event (e.g, http-kernel event, exception event) which utilizes [Symfony event dispatcher class interface](http://api.symfony.com/master/Symfony/Component/EventDispatcher/EventDispatcherInterface.html) as event dispatcher object and [Symfony event subscriber class interface](http://api.symfony.com/master/Symfony/Component/EventDispatcher/EventSubscriberInterface.html) as event subscriber (or listener collection) for current event dispatcher object.

This event dispatcher library uses several design patterns for extendibility and maintainability:

- [Observer Pattern](https://en.wikipedia.org/wiki/Observer_pattern) to maintain state between observer (listener) and observable (event) object.
- [Mediator Pattern](https://en.wikipedia.org/wiki/Mediator_pattern) to make all things truly extensible.

Table Of Content
================

[](#table-of-content)

- [Quick Start](#quick-start)
- [API](#api)
    - [EventDispatcherFactory](#eventdispatcherfactory)
    - [EventDispatcher](#eventdispatcher)

Quick Start
===========

[](#quick-start)

EventDispatcher object instantiation
------------------------------------

[](#eventdispatcher-object-instantiation)

```
use Gandung\EventDispatcher\EventDispatcher;
use Gandung\EventDispatcher\EventContainer;

$dispatcher = new EventDispatcher(new EventContainer);
```

or, you can do it with a factory.

```
use Gandung\EventDispatcher\EventDispatcherFactory;

$factory = new EventDispatcherFactory;
$dispatcher = $factory->getDispatcher();
```

Resolving events using simple closure based listener
----------------------------------------------------

[](#resolving-events-using-simple-closure-based-listener)

```
use Gandung\EventDispatcher\EventDispatcherFactory;

$factory = new EventDispatcherFactory;
$dispatcher = $factory->getDispatcher();
$listener = function() {
	echo "i'am a closure based listener.\n";
};

$dispatcher->attachListener('event.simple.closure', $listener, 20);
$dispatcher->dispatch('event.simple.closure');
```

Resolving events using simple object based listener
---------------------------------------------------

[](#resolving-events-using-simple-object-based-listener)

```
use Gandung\EventDispatcher\EventDispatcherFactory;

class Foo
{
	public function dummyResolver()
	{
		echo sprintf("Inside {%s}@{%s}", \spl_object_hash($this), __METHOD__);
	}
}

$foo = new Foo();
$factory = new EventDispatcherFactory;
$dispatcher = $factory->getDispatcher();
$dispatcher->attachListener('event.simple.object', [$foo, 'dummyResolver'], 20);
$dispatcher->dispatch('event.simple.object');
```

Resolving subscribed events
---------------------------

[](#resolving-subscribed-events)

```
use Gandung\EventDispatcher\EventDispatcherFactory;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class FooSubscriber implements EventSubscriberInterface
{
	public static function getSubscribedEvents()
	{
		return [
			'event.simple.prioritized' => [
				['dummyResolver1', 20],
				['dummyResolver2', 10],
				['dummyResolver3', -90]
			],
			'event.simple.unprioritized' => [
				'unprioritizedResolver'
			],
			'event.simple.single' => 'singleResolver'
		];
	}

	public function dummyResolver1()
	{
		echo sprintf("{%s@%s}\n", \spl_object_hash($this), __METHOD__);
	}

	public function dummyResolver2()
	{
		echo sprintf("{%s@%s}\n", \spl_object_hash($this), __METHOD__);
	}

	public function dummyResolver3()
	{
		echo sprintf("{%s@%s}\n", \spl_object_hash($this), __METHOD__);
	}

	public function unprioritizedResolver()
	{
		echo sprintf("{%s@%s}\n", \spl_object_hash($this), __METHOD__);
	}

	public function singleResolver()
	{
		echo sprintf("{%s@%s}\n", \spl_object_hash($this), __METHOD__);
	}
}

$subscriber = new FooSubscriber;
$factory = new EventDispatcherFactory();
$dispatcher->attachSubscriber($subscriber);
$dispatcher->dispatch('event.simple.prioritized');
$dispatcher->dispatch('event.simple.unprioritized');
$dispatcher->dispatch('event.simple.single');
```

API
===

[](#api)

EventDispatcherFactory
----------------------

[](#eventdispatcherfactory)

`getDispatcher()`

Return the EventDispatcher object instance.

EventDispatcher
---------------

[](#eventdispatcher)

`attachListener($event, $listener, $priority = 0)`

Append listener handler to specified event.

`detachListener($event, $listener)`

Remove listener handler to specified event.

`getListeners($event = null)`

Get listener that bind on specified event.

`hasListeners($event = null)`

Determine if specified event name has listeners.

`setListenerPriority($event, $listener, $priority)`

Set event listener priority.

`getListenerPriority($event, $listener)`

Get event listener priority.

`attachSubscriber(EventSubscriberInterface $subscriber)`

Register event subscriber.

`detachSubscriber(EventSubscriberInterface $subscriber)`

Remove event subscriber.

`dispatch($event, Event $eventHandler = null)`

Dispatch the specified event.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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

3171d ago

### Community

Maintainers

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

---

Top Contributors

[![plvhx](https://avatars.githubusercontent.com/u/12740518?v=4)](https://github.com/plvhx "plvhx (25 commits)")

### Embed Badge

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

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

###  Alternatives

[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[cognesy/instructor-php

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

310107.9k1](/packages/cognesy-instructor-php)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)[netgen/content-browser

Netgen Content Browser is a Symfony bundle that provides an interface which selects items from any kind of backend and returns the IDs of selected items back to the calling code.

14112.1k8](/packages/netgen-content-browser)[leapt/core-bundle

Symfony LeaptCoreBundle

2529.1k4](/packages/leapt-core-bundle)[ffi/var-dumper

List of symfony/var-dumper casters with FFI support

2010.7k4](/packages/ffi-var-dumper)

PHPackages © 2026

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