PHPackages                             semperton/events - 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. semperton/events

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

semperton/events
================

The Semperton Events component.

1.0.0(3y ago)026MITPHPPHP &gt;=7.4

Since Apr 26Pushed 3y agoCompare

[ Source](https://github.com/semperton/events)[ Packagist](https://packagist.org/packages/semperton/events)[ RSS](/packages/semperton-events/feed)WikiDiscussions main Synced 6d ago

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

[![Semperton](https://raw.githubusercontent.com/semperton/.github/main/readme-logo.svg)](https://github.com/semperton)Semperton Events
================

[](#semperton-events)

A minimal, PSR-14 compilant event library.

---

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

[](#installation)

Just use Composer:

```
composer require semperton/events

```

Events requires PHP 7.4+

Adding listeners
----------------

[](#adding-listeners)

Listeners are added with an event class or interface name, a listener callback and an optional priority value (default is 0, negative values allowed). The listener callback can be any PHP callable and should accept only one argument - the event object.

```
use Semperton\Events\ListenerProvider;

interface EventInterface{}
final class TestEvent implements EventInterface
{
	public $message = '';
}

$provider = new ListenerProvider();

$provider->addListener(TestEvent::class, function (TestEvent $event) {
	$event->message .= ' World';
});

$provider->addListener(EventInterface::class, function (EventInterface $event) {
	$event->message = 'Hello';
}, -1); // gets called first, because of higher priority (negatives allowed)
```

If you register a listener with an interface name, that listener will also be triggered if the dispatched event implements said interface.

Removing listeners
------------------

[](#removing-listeners)

Remove listeners with the `removeListener()` method. Event name, listener and priority must match.

```
$myListener = function (TestEvent $event) {};

$provider->addListener(TestEvent::class, $myListener, 7);
$provider->removeListener(TestEvent::class, $myListener, 7); // priority must match too
```

Dispatching
-----------

[](#dispatching)

All you need is a `ListenerProvider` (collection of event listeners) and an `EventDispatcher`.

```
use Semperton\Events\EventDispatcher;

// using the previously created ListenerProvider
$dispatcher = new EventDispatcher($provider);

$event = new TestEvent();

/** @var TestEvent */
$dispatchedEvent = $dispatcher->dispatch($event);

$dispatchedEvent === $event; // true
$dispatchedEvent->message; // 'Hello World'
```

DelegateListener example
------------------------

[](#delegatelistener-example)

If you want to call service methods in response to events, you may use a `callable` to resolve your services, etc. For this purpose a `DelegateListener` can be helpful:

```
$resolver = static function (string $class): object {
	return new $class();
};

$listener = new DelegateListener($resolver, Service::class, 'method');
```

Or use the `get` function of a PSR-11 Container as a resolver:

```
// $container is a Psr\Container\ContainerInterface
$listener = new DelegateListener([$container, 'get'], Service::class, 'method');
$provider->addListener(TestEvent::class, $listener);
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 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

Every ~185 days

Total

4

Last Release

1290d ago

Major Versions

0.0.3 → 1.0.02022-11-04

### Community

Maintainers

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

---

Top Contributors

[![jrabausch](https://avatars.githubusercontent.com/u/38224080?v=4)](https://github.com/jrabausch "jrabausch (30 commits)")

---

Tags

event-dispatchereventsphppsr-14semperton

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/semperton-events/health.svg)

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

###  Alternatives

[symfony/event-dispatcher-contracts

Generic abstractions related to dispatching event

3.4k756.5M424](/packages/symfony-event-dispatcher-contracts)[league/event

Event package

1.6k141.6M184](/packages/league-event)[phpro/soap-client

A general purpose SoapClient library

8885.6M46](/packages/phpro-soap-client)[yohang/finite

A simple PHP Finite State Machine

1.3k3.5M10](/packages/yohang-finite)[mcp/sdk

Model Context Protocol SDK for Client and Server applications in PHP

1.4k423.9k30](/packages/mcp-sdk)[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)

PHPackages © 2026

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