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

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

ifcanduela/events
=================

Tiny, simple events library

1.0.0(6y ago)0172↓91.7%1MITPHPCI failing

Since Sep 30Pushed 6y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (2)Used By (1)

ifcanduela/events
=================

[](#ifcanduelaevents)

Simple plug-and-play events library for any kind of project.

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

[](#installation)

Use [Composer](https://getcomposer.org):

```
composer require ifcanduela/events
```

Usage
-----

[](#usage)

Mixin the `\ifcanduela\events\CanEmitEvents` or `\ifcanduela\events\CanListenToEvents` traits into your classes and call the `emit()` or `listenTo()` methods.

Emitting events
---------------

[](#emitting-events)

An object will be able to emit events by using the `CanEmitEvents` trait and its `emit()` method.

An *event* may be a simple `string`, or an object of a class other than `stdClass`. If the event is a `string`, an optional `$payload` may be supplied and will be sent to the listener instead of the event string.

```
class MyEventType
{
    public $someProperty;

    public function __construct(int $data)
    {
        $this->someProperty = $data;
    }
}

class MyEventEmitter
{
    use \ifcanduela\events\CanEmitEvents;

    public function createData()
    {
        $data = random_int();

        // using an object as event
        $this->emit(new MyEventType($data));

        // using a string as event name; the array will be sent to the listener
        $this->emit("data.created", ["data" => $data]);
    }
}
```

Listening to events
-------------------

[](#listening-to-events)

An object will be able to listen to events by using the `CanListenToEvents`trait and calling `listenTo()`.

The event callback will receive the payload of the event, if any. In case of event objects, the `$payload` will be the event object itself, otherwise it will be whichever payload was passed by the emitter.

```
class MyEventListener
{
    public function __construct()
    {
        $this->listenTo(MyEventType::class, function ($event) {
            echo $event->someProperty;
        });

        $this->listenTo("data.created", function ($payload) {
            echo $payload["data"];
        });

        $this->listenTo("data.created", [$this, "eventHandler"]);
    }

    public function eventHandler($payload)
    {
        echo $payload["data"];
    }
}
```

Using the EventManager directly
-------------------------------

[](#using-the-eventmanager-directly)

The event manager lets your code emit and listen to events from outside objects. Replace `$object->emit()` with `EventManager::trigger()` and `$object->listenTo()`with `EventManager::register()`. These two static methods are used under the hood by the traits, so the functionality is exactly the same.

```
EventManager::register("event.name", function ($payload) {
    assert($payload["a"] === 1);
    assert($payload["b"] === 2);
});

EventManager::trigger("event.name", ["a" => 1, "b" => 2]);
```

License
-------

[](#license)

[MIT](LICENSE).

###  Health Score

27

—

LowBetter than 46% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

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

Unknown

Total

1

Last Release

2503d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1359230?v=4)[Igor Fernández Canduela](/maintainers/ifcanduela)[@ifcanduela](https://github.com/ifcanduela)

---

Top Contributors

[![ifcanduela](https://avatars.githubusercontent.com/u/1359230?v=4)](https://github.com/ifcanduela "ifcanduela (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[codercat/jwk-to-pem

Convert JWK to PEM format.

1005.0M31](/packages/codercat-jwk-to-pem)[nfephp-org/sped-da

sped-da contêm as classes para criação dos documentos auxiliares referidos no projeto Sped.

1531.0M18](/packages/nfephp-org-sped-da)[bnomei/kirby3-dotenv

Kirby Plugin for environment variables from .env

4151.3k2](/packages/bnomei-kirby3-dotenv)

PHPackages © 2026

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