PHPackages                             lufiipe/simplevent - 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. lufiipe/simplevent

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

lufiipe/simplevent
==================

Simple PHP event listener library

1.0.0(10mo ago)18541MITPHPPHP ^7.4|^8.0CI passing

Since Jun 26Pushed 10mo agoCompare

[ Source](https://github.com/lufiipe/simplevent)[ Packagist](https://packagist.org/packages/lufiipe/simplevent)[ RSS](/packages/lufiipe-simplevent/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (3)Used By (1)

[![GitHub Release](https://camo.githubusercontent.com/0cf1f1cca3d367f79192b0557104fcbaf4bb7df3548b15dcec2778d3750bd582/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6c7566696970652f73696d706c6576656e74)](https://github.com/lufiipe/simplevent/releases)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/611ad31acf901ffbdbd0d112c563ef131a332bf7eacb14ed39ff679bb804c934/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c7566696970652f73696d706c6576656e742f7068705f72756e5f74657374732e796d6c)](https://github.com/lufiipe/simplevent/actions)[![GitHub License](https://camo.githubusercontent.com/0e765dbfca5aee9fc0ad8475e8031676064aa3d5d13a6e041ac0b385356eccf6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c7566696970652f73696d706c6576656e743f636f6c6f723d79656c6c6f77)](LICENSE)

SimplEvent
==========

[](#simplevent)

Simple PHP event listener library.

With the ability to set a priority for each listener, pause/resume, define the number of times a listener can be triggered.

Install
-------

[](#install)

```
composer require lufiipe/simplevent

```

Usage
-----

[](#usage)

```
use LuFiipe\SimplEvent\Event;

Event::on('DummyEvent', function () {
    echo 'The dummy event listener has been triggered! ';
});

Event::emit('DummyEvent');
```

Usage with parameter

```
use LuFiipe\SimplEvent\Event;

Event::on('User.Logged', function ($user) {
    echo sprintf('%s is authenticated! ', $user['name']);
});

Event::emit('User.Logged', ['name' => 'John Doe']);
```

with multiple parameters

```
use LuFiipe\SimplEvent\Event;

Event::on('registered', function ($email, $ip, $device) {
    echo sprintf('"%s" registered from address "%s" with a "%s". ', $email, $ip, $device);
});

Event::emit('registered', 'john.doe@mail.net', '127.0.0.1', 'mobile');
```

An event can have multiple listeners.

```
use LuFiipe\SimplEvent\Event;

Event::on('User.Registered', function ($user) {
    echo 'Log user informations ';
});

Event::on('User.Registered', function ($user) {
    echo 'Send email to user ';
});

Event::emit('User.Registered', $user);
```

> #### Notice
>
> [](#notice)
>
> Listeners are triggered in the order of their declaration.

> #### Notice
>
> [](#notice-1)
>
> The event name must contain letters, numbers, dots, and underscores.

Priority
--------

[](#priority)

Since it is possible to attach multiple listeners to an event, it is also possible to assign a priority to each listener. More the priority value are higher, the sooner the listener will be called.

```
use LuFiipe\SimplEvent\Event;
use LuFiipe\SimplEvent\ListenerPriority;

Event::on('event.name', function () {
    echo 'Priority 10 ';
}, 10);

Event::on('event.name', function () {
    echo 'Priority Max ';
}, ListenerPriority::HIGH);

Event::on('event.name', function () {
    echo 'Priority 20 ';
}, 20);

Event::emit('event.name');
```

The above example will output:

```
Priority Max
Priority 20
Priority 10

```

Available priority constants

- `ListenerPriority::MAX` : Max priority
- `ListenerPriority::HIGH` : High priority
- `ListenerPriority::NORMAL` : Normal priority (by default)
- `ListenerPriority::LOW` : Low priority
- `ListenerPriority::MIN` : MIN priority

> #### Notice
>
> [](#notice-2)
>
> Like closures, priorities cannot be changed once declared.

Pause/Resume
------------

[](#pauseresume)

### Pause

[](#pause)

It is possible to pause the listeners

```
use LuFiipe\SimplEvent\Event;

$listner = Event::on('Comment.post', function ($comment) {
    echo sprintf('Comment posted: "%s" ', $comment);
});

Event::emit('Comment.post', 'Foo');

$listner->pause();

Event::emit('Comment.post', 'Bar');
```

The above example will output:

```
Comment posted: "Foo"

```

### Resume

[](#resume)

And to resume just use the `resume()` method of your listener.

```
use LuFiipe\SimplEvent\Event;

$listner = Event::on('Comment.post', function ($comment) {
    echo sprintf('Comment posted: "%s" ', $comment);
});

Event::emit('Comment.post', 'Foo');

$listner->pause();

Event::emit('Comment.post', 'Bar');

$listner->resume();

Event::emit('Comment.post', 'Baz');
```

The above example will output:

```
Comment posted: "Foo"
Comment posted: "Baz"

```

Run the listener multiple times
-------------------------------

[](#run-the-listener-multiple-times)

Specify the number of times the listener can be called.

In this example, the listeners for the "EventX" event will be triggered once.

```
use LuFiipe\SimplEvent\Event;
use LuFiipe\SimplEvent\ListenerTimes;

Event::on('EventX', function () {
})->setTimes(ListenerTimes::ONCE);
```

In the example below, listeners will be triggered three times.

```
use LuFiipe\SimplEvent\Event;

Event::on('Event.dummy', function ($number) {
    echo sprintf("triggered %d time(s) ", $number);
})->setTimes(3);

for ($i = 1; $i < 10; $i++) {
    Event::emit('Event.dummy', $i);
}
```

The above example will output:

```
triggered 1 time(s)
triggered 2 time(s)
triggered 3 time(s)

```

Available times constants

- `ListenerTimes::ALWAYS` : Always listen (by default)
- `ListenerTimes::NEVER` : Never listen
- `ListenerTimes::ONCE` : Listen one time

Remove all listeners from an event
----------------------------------

[](#remove-all-listeners-from-an-event)

```
Event::unregister('name');
```

Reset all events
----------------

[](#reset-all-events)

```
Event::reset();
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance53

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity42

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

Unknown

Total

1

Last Release

326d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/28425e09c9ba3f962ef94ce3ecbe688e74e0c6254591bd9a35a45dcf6dfd5c98?d=identicon)[lufiipe](/maintainers/lufiipe)

---

Top Contributors

[![lufiipe](https://avatars.githubusercontent.com/u/7064120?v=4)](https://github.com/lufiipe "lufiipe (1 commits)")

---

Tags

phpeventlisteneremitter

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/lufiipe-simplevent/health.svg)

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

###  Alternatives

[league/event

Event package

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

PHPackages © 2026

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