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

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

tbht/php-events
===============

a event emitter for php

1.0.0(5y ago)08931MITPHPCI failing

Since Oct 1Pushed 5y agoCompare

[ Source](https://github.com/sugar-libraries/php-events)[ Packagist](https://packagist.org/packages/tbht/php-events)[ RSS](/packages/tbht-php-events/feed)WikiDiscussions master Synced 1w ago

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

EventEmitter
============

[](#eventemitter)

[![PHP Composer](https://github.com/sugar-libraries/php-events/workflows/PHP%20Composer/badge.svg)](https://github.com/sugar-libraries/php-events/workflows/PHP%20Composer/badge.svg)[![codecov](https://camo.githubusercontent.com/ddc3b8678f4d0dfa93bd0fa265b84d51f5c4ede4dc382d70c0b7d61474d42d9a/68747470733a2f2f636f6465636f762e696f2f67682f73756761722d6c69627261726965732f7068702d6576656e74732f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/sugar-libraries/php-events)

Install
-------

[](#install)

`composer require tbht/php-events`

Usage
-----

[](#usage)

`add_listener`
--------------

[](#add_listener)

```
use Press\Utils\Events;

$ee = new Events();

$ee->add_listener('foo', function () {
    echo "this is a listener for php \n";
});

// the same as $ee->on()
$ee->on('foo', function () {
    echo "this is a listener for php \n";
});

$ee->emit('foo');

// the same as
$ee->emit_event('foo');
```

`remove_listener`
-----------------

[](#remove_listener)

### `string`

[](#string)

```
use Press\Utils\Events;

$ee = new Events();

$bar_listener = function ($arg) {
  var_dump($arg);
};

$ee->add_listener('bar', $bar_listener);

$ee->remove_listener('bar', $bar_listener);
```

### `regular expression`

[](#regular-expression)

```
use Press\Utils\Events;

$ee = new Events();
$fn1 = function () {};
$fn2 = function () {};
$fn3 = function () {};
$fn4 = function () {};
$fn5 = function () {};

$ee->add_listeners([
  'foo' => [$fn1, $fn2, $fn3, $fn4, $fn5],
  'bar' => [$fn1, $fn2, $fn3, $fn4, $fn5],
  'baz' => [$fn1, $fn2, $fn3, $fn4, $fn5]
]);

$ee->remove_listener('/ba[rz]/', $fn3);

assert(
  [$fn5, $fn4, $fn2, $fn1] === $ee->flatten_listeners($ee->get_listeners('bar'))
);
```

`add_once_listener`
-------------------

[](#add_once_listener)

```
use Press\Utils\Events;

$ee = new Events();
$counter = 0;

$bar_listener_once = function ($counter) use (&$counter) {
  $counter++;
};

$ee->add_once_listener('foo', $bar_listener_once);

$ee->emit('foo');
$ee->emit_event('foo');

assert($counter === 1, 'the counter should be 1');
```

`get_listeners`
---------------

[](#get_listeners)

```
use Press\Utils\Events;

$fn1 = function () {
    var_dump('this is first fn');
};

$fn2 = function () {
    var_dump('this is second fn');
};

$ee = new Events();
$ee->add_listeners('foo', $fn1)
   ->add_listeners('foo', $fn2);

// listeners is an array
$listeners = $ee->get_listeners('foo');
$listeners = $ee->flatten_listeners($listeners);
var_dump($listeners);
```

Advance Usage
-------------

[](#advance-usage)

### remove listeners with regex

[](#remove-listeners-with-regex)

```
use Press\Utils\Events;

$ee = new Events();

$fn1 = function () {};
$fn2 = function () {};
$fn3 = function () {};
$fn4 = function () {};
$fn5 = function () {};

$ee->add_listeners([
  'foo' => [$fn1, $fn2, $fn3, $fn4, $fn5],
  'bar' => [$fn1, $fn2, $fn3, $fn4, $fn5],
  'baz' => [$fn1, $fn2, $fn3, $fn4, $fn5]
]);

$ee->remove_listener('/ba[rz]/', $fn3);

$foo_list = $ee->get_listeners('foo');
$bar_list = $ee->get_listeners('bar');
$baz_list = $ee->get_listeners('baz');

count($foo_list) === 0;
count($bar_list) === 0;
count($baz_list) === 0;
```

### get listeners as `key-value`

[](#get-listeners-as-key-value)

```
$ee = new Events();
$ee->add_listener('bar', function () {});
$ee->add_listener('baz', function () {});

$listeners = $ee->get_listeners_wrapper('/ba[rz]/');

count($listeners['bar']) === 1;
count($listeners['baz']) === 1;
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

Established project with proven stability

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

Total

2

Last Release

2156d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10486739?v=4)[TbhT](/maintainers/TbhT)[@TbhT](https://github.com/TbhT)

---

Top Contributors

[![TbhT](https://avatars.githubusercontent.com/u/10486739?v=4)](https://github.com/TbhT "TbhT (13 commits)")

---

Tags

php-libraryphp7events

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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)[psr/event-dispatcher

Standard interfaces for event handling.

2.3k618.8M865](/packages/psr-event-dispatcher)[laminas/laminas-eventmanager

Trigger and listen to events within a PHP application

1.0k69.8M225](/packages/laminas-laminas-eventmanager)[simshaun/recurr

PHP library for working with recurrence rules

1.6k15.7M40](/packages/simshaun-recurr)[chelout/laravel-relationship-events

Missing relationship events for Laravel

5252.3M17](/packages/chelout-laravel-relationship-events)[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)
