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

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

jbzoo/event
===========

Library for event-based development

7.0.2(7mo ago)29760.0k—3.9%25MITPHPPHP ^8.2CI passing

Since Jan 28Pushed 7mo ago5 watchersCompare

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

READMEChangelog (10)Dependencies (2)Versions (28)Used By (5)

JBZoo / Event
=============

[](#jbzoo--event)

[![CI](https://github.com/JBZoo/Event/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/JBZoo/Event/actions/workflows/main.yml?query=branch%3Amaster) [![Coverage Status](https://camo.githubusercontent.com/30c3bb74ecc62965ff9155b92f5de79b1b3a0e375b012c1205e9be0bd5cfa661/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4a425a6f6f2f4576656e742f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/JBZoo/Event?branch=master) [![Psalm Coverage](https://camo.githubusercontent.com/6d1e5bc1b4f4d90abd3c2a1122572f4540f3a3c18ff8df73105b01109b9af378/68747470733a2f2f73686570686572642e6465762f6769746875622f4a425a6f6f2f4576656e742f636f7665726167652e737667)](https://shepherd.dev/github/JBZoo/Event) [![Psalm Level](https://camo.githubusercontent.com/1dd5ceb81df17a5a5d744c22db4f65c41cd9de8b85bcf0690d2cf56423059c2c/68747470733a2f2f73686570686572642e6465762f6769746875622f4a425a6f6f2f4576656e742f6c6576656c2e737667)](https://shepherd.dev/github/JBZoo/Event) [![CodeFactor](https://camo.githubusercontent.com/c68b2c856853cedd2d28d86e3e9065a7adeb99afa5143fd673e759d356816a27/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f6a627a6f6f2f6576656e742f6261646765)](https://www.codefactor.io/repository/github/jbzoo/event/issues)[![Stable Version](https://camo.githubusercontent.com/15693f2051313f425231c40c591c1f3338421bb426dab81f2684045b1322f3e3/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f6576656e742f76657273696f6e)](https://packagist.org/packages/jbzoo/event/) [![Total Downloads](https://camo.githubusercontent.com/882e39836b3839b677eaa067a85d986c21fe067f3d374d91c7cf49102756e6a0/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f6576656e742f646f776e6c6f616473)](https://packagist.org/packages/jbzoo/event/stats) [![Dependents](https://camo.githubusercontent.com/bbad08819364f342130663cfe64bdfcf51077a560f517f60a21808a829fab5e4/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f6576656e742f646570656e64656e7473)](https://packagist.org/packages/jbzoo/event/dependents?order_by=downloads) [![GitHub License](https://camo.githubusercontent.com/5016d9bbe6c5cedc30b2f3162f09496843615a010461de212bd6f110400dfd5a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a627a6f6f2f6576656e74)](https://github.com/JBZoo/Event/blob/master/LICENSE)

A lightweight PHP event manager library that provides a simple yet powerful pattern for event-driven development. Create objects that emit events and register listeners to handle them with support for priorities, namespaces, and wildcard matching.

Features
--------

[](#features)

- **Priority-based event handling** - Control execution order with built-in priority levels
- **Namespace support with wildcards** - Listen to `item.*`, `*.save`, or `*.*` patterns
- **Multiple callback types** - Closures, functions, static methods, and object methods
- **Event propagation control** - Stop event chains with `ExceptionStop`
- **One-time listeners** - Auto-removing listeners with `once()`
- **Reference parameter passing** - Communicate between listeners
- **High performance** - Optimized for speed with comprehensive benchmarks
- **PHP 8.2+ with strict types** - Modern PHP with full type safety

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

[](#installation)

```
composer require jbzoo/event
```

Usage
-----

[](#usage)

### Quick Start

[](#quick-start)

```
use JBZoo\Event\EventManager;

$eManager = new EventManager();

// Simple
$eManager->on('create', function () {
    echo "Something action";
});

// Just do it!
$eManager->trigger('create');
```

### Priority-Based Execution

[](#priority-based-execution)

By supplying a priority, you are ensured that subscribers handle in a specific order. The default priority is EventManager::MID. Anything below that will be triggered earlier, anything higher later. If there are two subscribers with the same priority, they will execute in an undefined, but deterministic order.

```
// Run it first
$eManager->on('create', function () {
    echo "Something high priority action";
}, EventManager::HIGH);

// Run it latest
$eManager->on('create', function () {
    echo "Something another action";
}, EventManager::LOW);

// Custom index
$eManager->on('create', function () {
    echo "Something action";
}, 42);

// Don't care...
$eManager->on('create', function () {
    echo "Something action";
});
```

### Callback Types

[](#callback-types)

All standard PHP callable types are supported:

```
$eManager->on('create', function(){ /* ... */ }); // Custom function
$eManager->on('create', 'myFunction');            // Custom function name
$eManager->on('create', ['myClass', 'myMethod']); // Static function
$eManager->on('create', [$object, 'Method']);     // Method of instance
```

### Event Propagation Control

[](#event-propagation-control)

```
use JBZoo\Event\ExceptionStop;

$eManager->on('create', function () {
    throw new ExceptionStop('Some reason'); // Special exception for JBZoo/Event
});

$eManager->trigger('create'); // Returns count of executed listeners
```

### Passing Arguments

[](#passing-arguments)

Event data can be passed to listeners as function arguments:

```
$eManager->on('create', function ($entityId) {
    echo "An entity with id ", $entityId, " just got created.\n";
});
$entityId = 5;
$eManager->trigger('create', [$entityId]);
```

Because you cannot really do anything with the return value of a listener, you can pass arguments by reference to communicate between listeners and back to the emitter.

```
$eManager->on('create', function ($entityId, &$warnings) {
    echo "An entity with id ", $entityId, " just got created.\n";
    $warnings[] = "Something bad may or may not have happened.\n";
});
$warnings = [];
$eManager->trigger('create', [$entityId, &$warnings]);
```

### Namespace Wildcards

[](#namespace-wildcards)

Use wildcards to listen to multiple related events:

```
$eManager->on('item.*', function () {
    // item.init
    // item.save
    echo "Any actions with item";
});

$eManager->on('*.init', function () {
    // tag.init
    // item.init
    echo "Init any entity";
});

$eManager->on('*.save', function () {
    // tag.save
    // item.save
    echo "Saving any entity in system";
});

$eManager->on('*.save.after', function () {
    // tag.save.after
    // item.save.after
    echo "Any entity on after save";
});

$eManager->trigger('tag.init');
$eManager->trigger('tag.save.before');
$eManager->trigger('tag.save');
$eManager->trigger('tag.save.after');

$eManager->trigger('item.init');
$eManager->trigger('item.save.before');
$eManager->trigger('item.save');
$eManager->trigger('item.save.after');
```

### One-Time Listeners

[](#one-time-listeners)

For events that should only be handled once:

```
$eManager->once('app.init', function () {
    echo "This will only run once, then auto-remove itself";
});

$eManager->trigger('app.init'); // Executes
$eManager->trigger('app.init'); // Does nothing - listener was removed
```

### Advanced Usage

[](#advanced-usage)

```
use JBZoo\Event\EventManager;

// Create a global event manager
EventManager::setDefault(new EventManager());
$globalManager = EventManager::getDefault();

// Get summary of registered events
$summary = $eManager->getSummeryInfo();
// Returns: ['user.create' => 3, 'user.update' => 1, ...]

// Remove specific listeners
$callback = function() { echo "test"; };
$eManager->on('test', $callback);
$eManager->removeListener('test', $callback);

// Remove all listeners for an event
$eManager->removeListeners('test');

// Remove ALL listeners
$eManager->removeListeners();
```

Performance Benchmarks
----------------------

[](#performance-benchmarks)

Extensive performance testing with 100,000 iterations shows excellent performance characteristics. Benchmark tests use [phpbench/phpbench](https://github.com/phpbench/phpbench) - see detailed results in [`tests/phpbench`](tests/phpbench).

> **Note:** `1μs = 1/1,000,000 of a second` - these are microseconds!

**benchmark: ManyCallbacks**

subjectgroupsitsrevsmeanstdevrstdevmem\_realdiffbenchOneUndefinedundefined101000000.65μs0.01μs1.00%6,291,456b1.00xbenchOneWithStarBegin\*.bar101000000.67μs0.01μs1.44%6,291,456b1.04xbenchOneWithAllStars\*.\*101000000.68μs0.03μs4.18%6,291,456b1.04xbenchOneWithStarEndfoo.\*101000000.68μs0.01μs1.24%6,291,456b1.04xbenchOneNestedfoo.bar1010000043.23μs0.46μs1.07%6,291,456b66.56xbenchOneSimplefoo1010000045.07μs2.63μs5.83%6,291,456b69.39x**benchmark: ManyCallbacksWithPriority**

subjectgroupsitsrevsmeanstdevrstdevmem\_realdiffbenchOneUndefinedundefined101000000.65μs0.01μs1.35%6,291,456b1.00xbenchOneNestedStarAll\*.\*101000000.67μs0.01μs1.34%6,291,456b1.03xbenchOneWithStarBegin\*.bar101000000.67μs0.01μs1.10%6,291,456b1.04xbenchOneWithStarEndfoo.\*101000000.68μs0.01μs1.13%6,291,456b1.05xbenchOneSimplefoo101000004.54μs0.02μs0.35%6,291,456b7.03xbenchOneNestedfoo.bar101000004.58μs0.04μs0.81%6,291,456b7.10x**benchmark: OneCallback**

subjectgroupsitsrevsmeanstdevrstdevmem\_realdiffbenchOneWithStarBegin\*.bar101000000.69μs0.03μs4.00%6,291,456b1.00xbenchOneWithStarEndfoo.\*101000000.70μs0.03μs4.22%6,291,456b1.00xbenchOneNestedStarAll\*.\*101000000.70μs0.04μs6.02%6,291,456b1.01xbenchOneUndefinedundefined101000000.71μs0.05μs7.44%6,291,456b1.02xbenchOneSimplefoo101000001.18μs0.03μs2.27%6,291,456b1.70xbenchOneNestedfoo.bar101000001.25μs0.03μs2.46%6,291,456b1.81x**benchmark: Random**

subjectgroupsitsrevsmeanstdevrstdevmem\_realdiffbenchOneSimplerandom.\*.triggers101000004.29μs0.33μs7.69%6,291,456b1.00xDevelopment
-----------

[](#development)

### Setup

[](#setup)

```
make update  # Install dependencies
```

### Testing

[](#testing)

```
make test      # Run PHPUnit tests
make test-all  # Run tests + code style checks
make codestyle # Run all linters
```

License
-------

[](#license)

MIT

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance62

Regular maintenance activity

Popularity47

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

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

Recently: every ~302 days

Total

27

Last Release

233d ago

Major Versions

1.4.2 → 2.0.02019-11-24

2.0.0 → 3.0.02020-07-14

3.2.3 → 4.0.02022-06-05

4.0.1 → 7.0.02023-07-09

PHP version history (8 changes)1.0.0PHP &gt;=5.4

1.2.0PHP &gt;=5.3

2.0.0PHP &gt;=7.1

3.0.0PHP &gt;=7.2

3.0.1PHP ^7.2

4.0.0PHP &gt;=7.4

7.0.0PHP ^8.1

7.0.2PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/75e6de2785f6d099699f430ff58404af4fc0e83060d2953028c9664a54704a5f?d=identicon)[smetdenis](/maintainers/smetdenis)

---

Top Contributors

[![SmetDenis](https://avatars.githubusercontent.com/u/1118678?v=4)](https://github.com/SmetDenis "SmetDenis (67 commits)")

---

Tags

callbackemitterevent-managementeventsjbzoolistenlistnerobservereventsevent managersignallisteneremitterobservereventmanagerHOOKjbzooemit

### Embed Badge

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

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

###  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.1k501.1M115](/packages/doctrine-event-manager)[league/event

Event package

1.6k141.6M184](/packages/league-event)[laminas/laminas-eventmanager

Trigger and listen to events within a PHP application

1.0k69.8M225](/packages/laminas-laminas-eventmanager)[tormjens/eventy

The WordPress filter/action system in Laravel

438912.9k16](/packages/tormjens-eventy)

PHPackages © 2026

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