PHPackages                             psr-discovery/event-dispatcher-implementations - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. psr-discovery/event-dispatcher-implementations

ActiveLibrary[HTTP &amp; Networking](/categories/http)

psr-discovery/event-dispatcher-implementations
==============================================

Lightweight library that discovers available PSR-14 Event Dispatcher implementations by searching for a list of well-known classes that implement the relevant interface, and returns an instance of the first one that is found.

1.2.0(1y ago)78.2M—7.2%11MITPHPPHP ^8.2

Since Mar 27Pushed 1y ago1 watchersCompare

[ Source](https://github.com/psr-discovery/event-dispatcher-implementations)[ Packagist](https://packagist.org/packages/psr-discovery/event-dispatcher-implementations)[ Docs](https://github.com/psr-discovery/http-client-implementations)[ RSS](/packages/psr-discovery-event-dispatcher-implementations/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (4)Dependencies (10)Versions (5)Used By (1)

**Lightweight library that discovers available [PSR-14 Event Dispatcher](https://www.php-fig.org/psr/psr-14/) implementations by searching for a list of well-known classes that implement the relevant interface, and returns an instance of the first one that is found.**

This package is part of the [PSR Discovery](https://github.com/psr-discovery) utility suite, which also supports [PSR-18 HTTP Clients](https://github.com/psr-discovery/http-client-implementations), [PSR-17 HTTP Factories](https://github.com/psr-discovery/http-factory-implementations), [PSR-11 Containers](https://github.com/psr-discovery/container-implementations), [PSR-6 Caches](https://github.com/psr-discovery/cache-implementations) and [PSR-3 Logs](https://github.com/psr-discovery/log-implementations).

This is largely intended for inclusion in libraries like SDKs that wish to support PSR-14 Event Dispatchers without requiring hard dependencies on specific implementations or demanding extra configuration by users.

- [Requirements](#requirements)
- [Implementations](#implementations)
- [Installation](#installation)
- [Usage](#usage)
- [Handling Failures](#handling-failures)
- [Exceptions](#exceptions)
- [Singletons](#singletons)
- [Mocking Priority](#mocking-priority)
- [Preferring an Implementation](#preferring-an-implementation)
- [Using a Specific Implementation](#using-a-specific-implementation)

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

[](#requirements)

- PHP 8.2+
- Composer 2.0+

Successful discovery requires the presence of a compatible implementation in the host application. This library does not install any implementations for you.

Implementations
---------------

[](#implementations)

The following `psr/event-dispatcher-implementation` implementations are discovered and instantiated automatically:

- [carlosas/simple-event-dispatcher](https://github.com/carlosas/simple-event-dispatcher) ^0.1.0
- [league/event](https://github.com/thephpleague/event) ^3.0
- [symfony/event-dispatcher](https://github.com/symfony/event-dispatcher) ^4.3 | ^5.0 | ^6.0 | ^7.0
- [yiisoft/event-dispatcher](https://github.com/yiisoft/event-dispatcher) ^1.0

The following mock implementations are also available:

- [psr-mock/event-dispatcher-implementation](https://github.com/psr-mock/event-dispatcher-implementation) ^1.0

If [a particular implementation](https://packagist.org/providers/psr/event-dispatcher-implementation) is missing that you'd like to see, please open a pull request adding support.

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

[](#installation)

```
composer require psr-discovery/event-dispatcher-implementations
```

Usage
-----

[](#usage)

```
use PsrDiscovery\Discover;

// Return an instance of the first discovered PSR-14 Event Dispatcher implementation.
$eventDispatcher = Discover::eventDispatcher();

// Send a request using the discovered Event Dispatcher.
eventDispatcher->dispatch(...);
```

Handling Failures
-----------------

[](#handling-failures)

If the library is unable to discover a suitable PSR-14 implementation, the `Discover::eventDispatcher()` discovery method will simply return `null`. This allows you to handle the failure gracefully, for example by falling back to a default implementation.

Example:

```
use PsrDiscovery\Discover;

$eventDispatcher = Discover::eventDispatcher();

if ($eventDispatcher === null) {
    // No suitable Event Dispatcher implementation was discovered.
    // Fall back to a default implementation.
    $eventDispatcher = new DefaultEventDispatcher();
}
```

Singletons
----------

[](#singletons)

By default, the `Discover::eventDispatcher()` method will always return a new instance of the discovered implementation. If you wish to use a singleton instance instead, simply pass `true` to the `$singleton` parameter of the discovery method.

Example:

```
use PsrDiscovery\Discover;

// $eventDispatcher1 !== $eventDispatcher2 (default)
$eventDispatcher1 = Discover::eventDispatcher();
$eventDispatcher2 = Discover::eventDispatcher();

// $eventDispatcher1 === $eventDispatcher2
$eventDispatcher1 = Discover::eventDispatcher(singleton: true);
$eventDispatcher2 = Discover::eventDispatcher(singleton: true);
```

Mocking Priority
----------------

[](#mocking-priority)

This library will give priority to searching for a known, available mocking library before searching for a real implementation. This is to allow for easier testing of code that uses this library.

The expectation is that these mocking libraries will always be installed as development dependencies, and therefore if they are available, they are intended to be used.

Preferring an Implementation
----------------------------

[](#preferring-an-implementation)

If you wish to prefer a specific implementation over others, you can `prefer()` it by package name:

```
use PsrDiscovery\Discover;
use PsrDiscovery\Implementations\Psr14\EventDispatchers;

// Prefer the a specific implementation of PSR-14 over others.
EventDispatchers::prefer('league/event');

// Return an instance of League\Event\Dispatcher,
// or the next available from the list of candidates,
// Returns null if none are discovered.
$dispatcher = Discover::eventDispatcher();
```

This will cause the `eventDispatcher()` method to return the preferred implementation if it is available, otherwise, it will fall back to the default behavior.

Note that assigning a preferred implementation will give it priority over the default preference of mocking libraries.

Using a Specific Implementation
-------------------------------

[](#using-a-specific-implementation)

If you wish to force a specific implementation and ignore the rest of the discovery candidates, you can `use()` its package name:

```
use PsrDiscovery\Discover;
use PsrDiscovery\Implementations\Psr14\EventDispatchers;

// Only discover a specific implementation of PSR-14.
EventDispatchers::use('league/event');

// Return an instance of League\Event\Dispatcher,
// or null if it is not available.
$dispatcher = Discover::eventDispatcher();
```

This will cause the `eventDispatcher()` method to return the preferred implementation if it is available, otherwise, it will return `null`.

---

This library is not produced or endorsed by, or otherwise affiliated with, the PHP-FIG.

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity51

Moderate usage in the ecosystem

Community12

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 95.7% 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 ~155 days

Total

5

Last Release

529d ago

PHP version history (3 changes)1.0.0PHP ^8.0

1.1.1PHP ^8.1

1.2.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3093?v=4)[Evan Sims](/maintainers/evansims)[@evansims](https://github.com/evansims)

---

Top Contributors

[![evansims](https://avatars.githubusercontent.com/u/3093?v=4)](https://github.com/evansims "evansims (22 commits)")[![JanMikes](https://avatars.githubusercontent.com/u/3995003?v=4)](https://github.com/JanMikes "JanMikes (1 commits)")

---

Tags

discoveryevent-dispatcherevent-dispatcher-implementationpsrpsr-14psrpsr-18discovery

###  Code Quality

TestsPest

Static AnalysisPHPStan, Psalm, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/psr-discovery-event-dispatcher-implementations/health.svg)

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

###  Alternatives

[psr/http-client

Common interface for HTTP clients

1.7k680.7M2.1k](/packages/psr-http-client)[psr/http-message

Common interface for HTTP messages

7.1k1.0B5.5k](/packages/psr-http-message)[psr/http-factory

PSR-17: Common interfaces for PSR-7 HTTP message factories

1.9k692.9M1.9k](/packages/psr-http-factory)[psr/link

Common interfaces for HTTP links

2.5k144.1M68](/packages/psr-link)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[laminas/laminas-diactoros

PSR HTTP Message implementations

548105.8M965](/packages/laminas-laminas-diactoros)

PHPackages © 2026

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