PHPackages                             symbiotic/event-contracts - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. symbiotic/event-contracts

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

symbiotic/event-contracts
=========================

Extend Interfaces for PSR 14 EventDispatcher

1.4.0(3y ago)01211MITPHPPHP &gt;=8.0

Since Aug 29Pushed 3y agoCompare

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

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

Extend interfaces for PSR-14 Event Dispatcher
---------------------------------------------

[](#extend-interfaces-for-psr-14-event-dispatcher)

README.RU.md [РУССКОЕ ОПИСАНИЕ](https://github.com/symbiotic-php/event-contracts/blob/master/README.RU.md)

Added a method for adding listeners with passing the event name and the ability to pass the class name as a listener. This approach avoids the use of Reflection when adding listeners, as well as unnecessary closure objects.

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

[](#installation)

```
composer require symbiotic/event-contracts

suggest symbiotic/event - reailsation

```

Description
-----------

[](#description)

```
use \Psr\EventDispatcher\ListenerProviderInterface;

interface ListenersInterface extends ListenerProviderInterface
{
    /**
     * @param string $event the class name or an arbitrary event name
     * (with an arbitrary name, you need a custom dispatcher not for PSR)
     *
     * @param \Closure|string $handler function or class name of the handler
     * The event handler class must implement the handle method  (...$params) or __invoke(...$params)
     * Important! When adding listeners as class names, you will need to adapt them to \Closure
     * when you return them in the getListenersForEvent() method!!!
     *
     * @return void
     */
    public function add(string $event, $handler): void;
}
```

Sample implementation of the \\Closure wrapper:

```
$listenerResolver = function($listener) {
    return function(object $event) use ($listener) {
            // if classname
            if(is_string($listener) && class_exists($listener)) {
                $listener = new $listener();
                return $listener->handle($event);
            } elseif(is_callable($listener)) {
                return $listener($event);
            }
    };
};
// You can implement your wrapper directly in the getListenersForEvent() method or throw a resolver with a PSR container

class ListenerProvider implements Symbiotic\Event\ListenersInterface
{
    protected $listenerResolver;

    protected $listeners = [];

    public function __construct(\Closure $listenerResolver = null)
    {
        $this->listenerResolver = $listenerResolver;
    }

    public function add(string $event, $handler): void
    {
        $this->listeners[$event][] = $handler;
    }

    public function getListenersForEvent(object $event): iterable
    {
        $parents = \class_parents($event);
        $implements = \class_implements($event);
        $classes = array_merge([\get_class($event)], $parents ?: [], $implements ?: []);
        $listeners = [];
        foreach ($classes as $v) {
            $listeners = array_merge($listeners, isset($this->listeners[$v]) ? $this->listeners[$v] : []);
        }
        $wrapper = $this->listenerResolver;

        return $wrapper ? array_map(function ($v) use ($wrapper) {
            return $wrapper($v);
        }, $listeners) : $listeners;

    }
}

/**
 *  use resolver
 **/
$listenersProvider = new \Symbiotic\Event\ListenerProvider($listenerResolver);
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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

Total

2

Last Release

1336d ago

PHP version history (2 changes)1.0.1PHP &gt;=7.2.0

1.4.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/a7ef7750fdc43614c00e641939b148f999b2771b930cf3cf1b18c66fe614de9c?d=identicon)[symbiotic](/maintainers/symbiotic)

---

Tags

psr-14event dispatchersymbioticPSR-14 Event Dispatcher

### Embed Badge

![Health badge](/badges/symbiotic-event-contracts/health.svg)

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

###  Alternatives

[yiisoft/event-dispatcher

Yii Event Dispatcher

72900.2k24](/packages/yiisoft-event-dispatcher)[tommyknocker/pdo-database-class

Framework-agnostic PHP database library with unified API for MySQL, MariaDB, PostgreSQL, SQLite, MSSQL, and Oracle. Query Builder, caching, sharding, window functions, CTEs, JSON, migrations, ActiveRecord, CLI tools, AI-powered analysis. Zero external dependencies.

845.7k](/packages/tommyknocker-pdo-database-class)[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)
