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

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

unique/events
=============

Provides basic event functionality.

1.0.2(4y ago)0702MITPHPPHP &gt;=7.4

Since Nov 2Pushed 4y ago1 watchersCompare

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

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

Events
======

[](#events)

This package provides a very basic events system.

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

[](#installation)

This component requires php &gt;= 7.4. To install it, you can use composer:

```
composer require unique/events

```

Usage
-----

[](#usage)

Let's say you want to create a file loader, which will load the file and throw an event with file's content.
In that case you first have to created a simple event object. Let's call it `FileLoadEvent`.

```
    class FileLoadEvent implements \unique\events\interfaces\EventObjectInterface {

        use \unique\events\traits\EventObjectTrait;

        public ? string $contents = null;
    }
```

Now let's write a simple file loader class:

```
    class FileLoader implements \unique\events\interfaces\EventHandlingInterface {

        const EVENT_AFTER_LOAD = 'after_load';

        use \unique\events\traits\EventTrait;

        public function load() {

            // ...some logic to load the file and set $contents value
            $event_object = new FileLoadEvent();
            $event_object->contents = $contents;

            $this->trigger( self::EVENT_AFTER_LOAD, $event_object );
            return $event_object->getHandled();
        }
    }
```

Now you can use your defined event functionality by adding an event handler:

```
    $obj = new FileLoader();
    $obj->on( FileLoader::EVENT_AFTER_LOAD, function ( FileLoadEvent $event_object ) {

        if ( $event_object->contents !== '' ) {

            // do something...
            $event_object->setHandled( true );
        }
    } );
    $obj->getContents();
```

What this does is it defines an event handler for `EVENT_AFTER_LOAD` event. The handler does some logic and marks the event as handled.
If you were to have more than one handler defined for the same event, events would propagate up until all handlers have been called or until one of the handlers sets `handled` attribute to `true`.

Documentation
-------------

[](#documentation)

#### `on( string $event, $callback )`

[](#on-string-event-callback-)

Sets a new handler for the specified event type.

- `string $event` - Event name. It is a good idea to define these events as constants on the triggering class.
- `\Closure|array $callback` - Handler of the event. Will receive one parameter: `( EventObjectInterface $event )`

#### `trigger( string $event_name, EventObjectInterface $event )`

[](#trigger-string-event_name-eventobjectinterface-event-)

Triggers the specified event. The first assigned handler will be called first. If it does not set `EventObjectInterface::setHandled()` the second handler will be called and so on, until all the handlers have been called or `setHandled( true )` has been set.

- `string $event_name` - Event name. It is a good idea to define these events as constants on the triggering class.
- `EventObjectInterface $event` - Event object

#### `off( string $event, $callback = null )`

[](#off-string-event-callback--null-)

Removes an event handler from the object. If no handler is provided all handlers will be removed.

- `string $event` - Event name. It is a good idea to define these events as constants on the triggering class.
- `\Closure|array|null $callback` - Handler of the event that was previously assigned using `on()`.

###  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

Maturity57

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

Total

4

Last Release

1657d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a798acb845b9c8ab35c7853f5a6bfd5e3b2b0578faea86e873fa269ea997371?d=identicon)[unique](/maintainers/unique)

---

Top Contributors

[![uniquexor](https://avatars.githubusercontent.com/u/6176836?v=4)](https://github.com/uniquexor "uniquexor (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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