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

ActiveLibrary

proteins/event
==============

Event emitter-listener global class and behaviour trait

1.0.1(6y ago)0502MITPHPPHP ^7.2

Since May 28Pushed 6y ago1 watchersCompare

[ Source](https://github.com/php-protein/event)[ Packagist](https://packagist.org/packages/proteins/event)[ RSS](/packages/proteins-event/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (3)Used By (2)

[![](https://raw.githubusercontent.com/php-protein/docs/master/assets/protein-large.png)](https://raw.githubusercontent.com/php-protein/docs/master/assets/protein-large.png)

Protein | Events
================

[](#protein--events)

Event emitter-listener global class and behaviour trait
-------------------------------------------------------

[](#event-emitter-listener-global-class-and-behaviour-trait)

### Install

[](#install)

---

```
composer require proteins/event

```

Require the global class via :

```
use Proteins\Event;
```

or the include the trait in your classes via :

```
use Proteins\Events;

class MyClass {
    use Events;
}
```

### Attach an handler

[](#attach-an-handler)

---

You can attach an handler to a named event via the `on` method.

```
Event::on('my.event',function(){
   echo 'Hello, Friend!';
});
```

Multiple handlers can be attached to the event, they will be sequentially executed when the event will be triggered.

```
Event::on('my.event',function(){
   echo 'First!';
});

Event::on('my.event',function(){
   echo 'Second!';
});
```

You can attach handlers to any event name.

### Trigger an event

[](#trigger-an-event)

---

You can trigger an event via the `trigger` method.

```
Event::trigger('my.event');
```

The `trigger` method will return an array containing the return values of all the handler attached to the event.

**Example**

```
Event::on('my.event',function(){
   return 'Hello!';
});

Event::on('my.event',function(){
   return time();
});

$results = Event::trigger('my.event');
```

The `$results` variable contains :

```
array(2) {
 [0]  =>  string(6) "Hello!"
 [1]  =>  int(1389115191)
}
```

`NULL` will be returned if no handlers are attached to the event.

You can run a trigger only one time with the `triggerOnce` method.

### Passing parameters to event handlers

[](#passing-parameters-to-event-handlers)

---

You can pass a variable number of parameter to event handlers appending them after the event name in the `trigger` method.

```
Event::on('eat',function($who,$what,$where){
   echo "$who ate a $what, in the $where.";
});

Event::trigger('eat','Simon','Burrito','Kitchen');

// Result : Simon ate a Burrito, in the Kitchen
```

### Using the Events trait

[](#using-the-events-trait)

---

You can augment any existing class adding the Events trait to them. The Events trait has the same identically signature of the standard Event module (in fact the Event Module is a simple wrapper of the Events trait).

```
class Game {
  use Events;
  public static function loadLevel($name){
    ...
    self::trigger("level.loaded", $name);
  }
}

Game::on("level.start",function($level_name){
  echo "Starting {$level_name}, BRING'EM'ON!!!\n";
});

Game::on("level.loaded",function($level_name){
  echo "Reticulating splines for {$level_name}...\n";
  Game::trigger("level.start", $level_name);
});

Game::on("level.start",function($level_name){
  echo "Replenish ammonitions...\n";
});

Game::loadLevel("E1M1");
```

```
Reticulating splines for E1M1...
Starting E1M1, BRING'EM'ON!!!
Replenish ammonitions...

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community11

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

Total

2

Last Release

2543d ago

### Community

Maintainers

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

---

Top Contributors

[![lastguest](https://avatars.githubusercontent.com/u/178900?v=4)](https://github.com/lastguest "lastguest (5 commits)")

### Embed Badge

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

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

PHPackages © 2026

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