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

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

sugiphp/events
==============

Observer design pattern-like events system

1.0.0(11y ago)36662MITPHPPHP &gt;=5.3

Since Dec 16Pushed 9y ago2 watchersCompare

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

READMEChangelog (1)DependenciesVersions (2)Used By (2)

Events
======

[](#events)

[![Build Status](https://camo.githubusercontent.com/54a8936828c52e1881b790043bf246ada4ff5a6156863196ad424173a0f4b2bb/68747470733a2f2f7472617669732d63692e6f72672f537567695048502f4576656e74732e706e67)](https://travis-ci.org/SugiPHP/Events)

Observer design pattern-like events system.

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

[](#installation)

```
composer require sugiphp/events ~1.0
```

Usage
-----

[](#usage)

### Event

[](#event)

Event is a simple object identified by it's unique name. When an event is fired the Event Dispatcher notifies registered listeners for that particular event name.

### Listener

[](#listener)

Any function or method that takes no more than one argument can act as a listener. When an event is fired the dispatcher calls all registered listeners (functions) one by one.

### Dispatcher

[](#dispatcher)

Dispatcher have most significant role in the events systems. All events are fired via the dispatcher. The dispatcher checks for any listeners that are registered with that event and notifies them.

```
// create a dispatcher
$dispatcher = new Dispatcher();
// register one or more listeners for one or more events
$dispatcher->addListener("user.login", function ($event) {
    // this function will be executed when an event with name "user.login" is fired
});

// fires an event
$dispatcher->dispatch(new Event("user.login"));
```

### Passing data

[](#passing-data)

All listeners should have only one parameter - the event. If we need to pass additional info to those functions we can transport the date with the Event.

```
$dispatcher->addListener("user.login", function ($event) {
    // get one property
    echo $event->getParam("id"); // 1
    // get a property as Array
    echo $event["username"]; // "demo"
    // fetch all data
    $event->getParams(); // array("id" => 1, "username" => "demo")
});
$event = new Event("user.login", array("id" => 1, "username" => "demo"));
$dispatcher->dispatch($event);
```

You might need to exchange data between one listener and another. You can do that by adding and altering the data in the event with `setParam()` method.

```
$dispatcher->addListener("user.login", function ($event) {
    if ("mike" == $event["username"]) {
        // array access
        $event["is_admin"] = true;
    } else {
        // using setParam() method
        $event->setParam("is_admin", false);
    }
});

$dispatcher->addListener("user.login", function ($event) {
    if ($event["is_admin"]) {
        echo "Hello Admin";
    }
});

$event = new Event("user.login", array("username" => "mike"));
$dispatcher->dispatch($event);
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

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

4162d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/991c2430ace2ac70cb06507ae39e9e556e43bff5380e45ddd72c0f0294347794?d=identicon)[tzappa](/maintainers/tzappa)

---

Top Contributors

[![tzappa](https://avatars.githubusercontent.com/u/140298?v=4)](https://github.com/tzappa "tzappa (24 commits)")

---

Tags

eventobserverdispatcher

### Embed Badge

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

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

###  Alternatives

[contributte/event-dispatcher

Best event dispatcher / event manager / event emitter for Nette Framework

292.4M19](/packages/contributte-event-dispatcher)

PHPackages © 2026

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