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

ActiveLibrary

kanellov/php-events
===================

A simple events manager

2.0.0(10y ago)056GNU GPLv3PHPPHP &gt;=5.3

Since Feb 7Pushed 10y ago1 watchersCompare

[ Source](https://github.com/kanellov/php-events)[ Packagist](https://packagist.org/packages/kanellov/php-events)[ RSS](/packages/kanellov-php-events/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

php-events
==========

[](#php-events)

masterdevelop[![Build Status](https://camo.githubusercontent.com/466cb8708bcaea173df563869f9bccd068c81f8f638a08c7cc2df1d2c3c9a7bb/68747470733a2f2f7472617669732d63692e6f72672f6b616e656c6c6f762f7068702d6576656e74732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kanellov/php-events)[![Build Status](https://camo.githubusercontent.com/9b1f5445d826b7b0508f4f78f963b76f38d545c6e82309bfc0613f8ee8763338/68747470733a2f2f7472617669732d63692e6f72672f6b616e656c6c6f762f7068702d6576656e74732e7376673f6272616e63683d646576656c6f70)](https://travis-ci.org/kanellov/php-events)An single instance event manager, implemented with a simple php function. It allows you to attach and detach listeners to named events, trigger events and interrupt listeners from executing.

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

[](#requirements)

- php &gt;= 5.3

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

[](#installation)

```
$ composer require kanellov/php-events

```

Basic features
--------------

[](#basic-features)

- **Set priority to listeners for each event.**When attaching a listener, you can set the priority by specifying an integer as the last argument. Listeners with greater priority value will be triggered first.
- **Collect listeners results when triggering an event.**The return values from each listener are collected when triggering and returned in an array, ordered according to listeners.
- **Stop event from propagating.**Events can be stopped at any time from listeners. Each listener receives a callable as the last argument, which prevents triggering the following listeners. The `stopped` flag is contained in the triggering results.
- **Wildcard event.**You can use the wildcard event `*` to attach to all events. If priority is specified it will be used for this listener for any event triggered.

Usage
-----

[](#usage)

### Attaching listeners

[](#attaching-listeners)

- `\Knlv\events('on', string $event_name, callable $listener[, int $priority]);` registers a `$listener` for event `$event_name`
- `\Knlv\events('on', '*', callable $listener[, int priority])` registers a `$listener` for all events

**Note:** *All listeners receive an extra last argument. It' s a callable that stops event propagation if called.*

### Triggering event

[](#triggering-event)

- `\Knlv\events('trigger', string $event_name [, mixed $...]);` triggers the `$event_name` event and passes args to listeners.

### Detaching listeners

[](#detaching-listeners)

- `\Knlv\events('off');` detaches all listeners
- `\Knlv\events('off', $event_name)` detaches all listeners for event `$event_name`
- `\Knlv\events('off', $event_name, $listener)` detaches a certain `$listener` for event `$event_name`

Examples
--------

[](#examples)

### Attach listeners and trigger event

[](#attach-listeners-and-trigger-event)

```
\Knlv\events('on', 'event_name', function ($value) {
    return strtolower($value);
});

\Knlv\events('on', 'event_name', function ($value) {
    return strtoupper($value);
});

$result = \Knlv\events('trigger', 'event_name', 'TEST');

var_dump($result);

/*
array(2) {
  'stopped' =>
  bool(false)
  'results' =>
  array(2) {
    [0] =>
    string(4) "test"
    [1] =>
    string(4) "TEST"
  }
}
*/
```

### Specifying priority

[](#specifying-priority)

```
\Knlv\events('on', 'event_name', function ($value) {
    return strtolower($value);
});

\Knlv\events('on', 'event_name', function ($value) {
    return strtoupper($value);
}, 10);

$result = \Knlv\events('trigger', 'event_name', 'TEST');

var_dump($result);

/*
array(2) {
  'stopped' =>
  bool(false)
  'results' =>
  array(2) {
    [0] =>
    string(4) "TEST"
    [1] =>
    string(4) "test"
  }
}
*/
```

### Stopping event propagation

[](#stopping-event-propagation)

```
\Knlv\events('on', 'event_name', function ($value, $stop) {
    $stop();
    return strtolower($value);
});

\Knlv\events('on', 'event_name', function ($value) {
    return strtoupper($value);
});

$result = \Knlv\events('trigger', 'event_name', 'TEST');

var_dump($result);

/*
array(2) {
  'stopped' =>
  bool(true)
  'results' =>
  array(1) {
    [0] =>
    string(4) "test"
  }
}
*/
```

License
-------

[](#license)

The php-events is licensed under the GNU GENERAL PUBLIC LICENSE Version 3. See [License File](LICENSE) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Total

2

Last Release

3745d ago

Major Versions

1.0.0 → 2.0.02016-02-11

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1442736?v=4)[Vassilis Kanellopoulos](/maintainers/kanellov)[@kanellov](https://github.com/kanellov)

---

Top Contributors

[![kanellov](https://avatars.githubusercontent.com/u/1442736?v=4)](https://github.com/kanellov "kanellov (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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