PHPackages                             gobline/mediator - 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. gobline/mediator

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

gobline/mediator
================

Mediator component

v3.0.0(10y ago)21401BSD-3-ClausePHPPHP &gt;=5.6.0

Since Nov 13Pushed 9y ago1 watchersCompare

[ Source](https://github.com/gobline/mediator)[ Packagist](https://packagist.org/packages/gobline/mediator)[ Docs](https://github.com/gobline)[ RSS](/packages/gobline-mediator/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (7)Used By (1)

Mediator component
==================

[](#mediator-component)

The Mediator component allows your application components to communicate with each other by dispatching events and listening to them. It implements the mediator behavioral design pattern.

### Creating the Dispatcher

[](#creating-the-dispatcher)

```
use Gobline\Mediator\EventDispatcher;

$dispatcher = new EventDispatcher();
```

### Adding Event Subscribers

[](#adding-event-subscribers)

```
use Gobline\Mediator\EventSubscriberInterface;

class FooSubscriber implements EventSubscriberInterface
{
    public function onFooEvent()
    {
        // ... do something
    }

    public function getSubscribedEvents()
    {
        return ['fooEvent' => 'onFooEvent'];
    }
}

$subscriber = new FooSubscriber();
$dispatcher->addSubscriber($subscriber);
```

### Adding Event Listeners

[](#adding-event-listeners)

Event listeners are similar to event subscribers. The only difference is that an event listener doesn't need to implement the *EventSubscriberInterface* interface and provide the events it listens to. Instead, you specify the events it listens to outside the class. The equivalent of the sample above using an event listener would be:

```
class FooListener
{
    public function onFooEvent()
    {
        // ... do something
    }
}

$listener = new FooListener();
$dispatcher->addListener($listener, ['fooEvent' => 'onFooEvent']);
```

### Lazy Listeners

[](#lazy-listeners)

You can add a closure which will lazy load the listener instance. This allows the listener to be instantiated only when an event it listens to is dispatched.

```
$dispatcher->addListener(
    function() { return new FooListener(); },
    ['fooEvent' => 'onFooEvent']);
```

### Dispatching Events

[](#dispatching-events)

```
$dispatcher->dispatch('fooEvent');
```

Passing event data
------------------

[](#passing-event-data)

```
$dispatcher->dispatch('fooEvent', ['foo' => 'bar']);

class FooListener
{
    public function onFooEvent(array $data)
    {
        // ... do something with $data['foo']
    }
}
```

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

[](#installation)

You can install the Mediator component using the dependency management tool [Composer](https://getcomposer.org/). Run the *require* command to resolve and download the dependencies:

```
composer require gobline/mediator

```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity62

Established project with proven stability

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 ~77 days

Recently: every ~88 days

Total

6

Last Release

3864d ago

Major Versions

v1.1.0 → v2.0.02014-12-15

v2.0.1 → v3.0.02015-12-03

PHP version history (2 changes)v1.0.0PHP &gt;=5.5.0

v3.0.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1564a230fe2f5125b0504cf6b6fe1e829face1a5d20ec663b3b8d22843312c7d?d=identicon)[mdecaffmeyer](/maintainers/mdecaffmeyer)

---

Tags

event dispatchermediatorgobline

### Embed Badge

![Health badge](/badges/gobline-mediator/health.svg)

```
[![Health](https://phpackages.com/badges/gobline-mediator/health.svg)](https://phpackages.com/packages/gobline-mediator)
```

###  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.0k526.1M156](/packages/doctrine-event-manager)[evenement/evenement

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

1.4k167.3M339](/packages/evenement-evenement)[phly/phly-event-dispatcher

Experimental event dispatcher for PSR-14

26284.5k6](/packages/phly-phly-event-dispatcher)[slince/event-dispatcher

Event dispatcher package

106.1k2](/packages/slince-event-dispatcher)

PHPackages © 2026

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