PHPackages                             chipslays/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. chipslays/event

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

chipslays/event
===============

A simple event dispatching mechanism (like routing) for chat bots.

2.0.2(3y ago)13672MITPHP

Since Feb 19Pushed 3y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (20)Used By (2)

☎ Event
=======

[](#-event)

[![GitHub Workflow Status](https://camo.githubusercontent.com/3ddb639ba294422abb47bd220d1e76071fbe35e8a570ed75dbeef72eb50fbf73/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f63686970736c6179732f6576656e742f5465737473)](https://camo.githubusercontent.com/3ddb639ba294422abb47bd220d1e76071fbe35e8a570ed75dbeef72eb50fbf73/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f63686970736c6179732f6576656e742f5465737473)[![Packagist Version](https://camo.githubusercontent.com/b2e02cc6bf85f1c83e8cddeb37284571f418ed963c0651b1375e7c3c313c1b76/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63686970736c6179732f6576656e74)](https://camo.githubusercontent.com/b2e02cc6bf85f1c83e8cddeb37284571f418ed963c0651b1375e7c3c313c1b76/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63686970736c6179732f6576656e74)

A simple event dispatching mechanism (like routing) for chat bots and not only.

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

[](#installation)

```
$ composer require chipslays/event
```

Methods
-------

[](#methods)

#### `__construct($data)`

[](#__constructdata)

Parameter `$data` must be a `array`, `json`, `stdClass` or instance of `Chipslays\Collection\Collection`.

#### `on(string $event, callable|string|array $fn [, int $sort = 500]): Event`

[](#onstring-event-callablestringarray-fn--int-sort--500-event)

Paramater `$fn` must be a function or class (support static and non-static methods).

```
$event->on(..., function () {...}, $sort);
$event->on(..., '\App\Controller@method', $sort);
```

Pass any args for `$fn`:

```
$event->on(..., [function ($param1, $param2) {...}, $param1, $param2], $sort);
$event->on(..., ['\App\Controller@method', $param1, $param2], $sort);
```

Pass `$event = true` for force execute event.

```
$event->on(true, ..., ...);
```

Parameter `$sort` responsible for the execution priority.

#### `run(): void`

[](#run-void)

Dispatch and execute all caught events.

Usage
-----

[](#usage)

```
use Chipslays\Event\Event;

require __DIR__ . 'vendor/autoload.php';

$event = new Event([
    'message' => [
        'text' => 'hello',
    ],
    'user' => [
        'id' => 1234567890,
        'firstname' => 'John',
        'lastname' => 'Doe'
    ],
]);

// Callable function
$event->on('message.text', function () {
    echo 'This event has `text`';
});

// Class
$event->on('message.text', '\App\SomeController@greeting');

$event->run();
```

```
$event->on(['message.text' => 'hello'], function () {
    echo 'Hello 👋';
});
```

```
$event->on(['*.text' => 'hello'], function () {
    echo 'Hello 👋';
});
```

```
// At least one "OR Bye OR Goodbye" logic
$event->on([['message.text' => 'Bye'], ['message.text' => 'Goodbye']], function () {
    echo 'Bye!';
});
```

```
$event->on(['*.text' => 'My name is {name}'], function ($name) {
    echo "Nice to meet you, {$name}!";
});
```

```
// {user} - is a required parameter, he should be in text
// {:time?} - is a optional parameter, it may not be in text
$event->on(['*.text' => '/ban {user} {:time?}'], function ($user = null, $time = null) {
    echo "Banned: {$user}, time:" . $time ?? strtotime('+7 day');
});
```

```
$event->on('{message}', function ($message) {
    echo "Your message: {$message}";
});
```

```
$event->on(['*.text' => '/^hello$/i'], function () {
    echo "Hello!";
});
```

```
// For prevent chain function must return False
$event->on(['*.text' => 'Hi!'], function () {
    echo "Hello!";
    return false;
});

$event->on(['*.firstname' => 'John'], function () {
    echo "This text will never be displayed";
});
```

```
// You can use sort for events
$event->on(['*.firstname' => 'John'], function () {
    echo "This text will never be displayed";
}, 500);

$event->on(['*.text' => 'Hi!'], function () {
    echo "Hello!";
    return false;
}, 400);
```

```
// Pass callback args
$event->on('something', [function ($name, $email) {
    ...
}, 'John', 'test@ema.il']);

$event->on('something', ['SomeController@insert', 'John', 'test@ema.il']);
```

Own Event class
---------------

[](#own-event-class)

You can use events in your class by trait:

```
use Chipslays\Event\EventTrait;

class MyClass
{
    use EventTrait;

    // ...
}
```

Redefine methods `on`, `run`:

```
use Chipslays\Event\EventTrait;

// Redefine methods in other trait
trait MyEventTrait
{
    /**
     * @param array|string $event
     * @param callable|string|array $callback
     * @param integer $sort
     * @return void
     */
    public function on($event, $callback, int $sort = 500)
    {
        // do something before...

        $this->addEvent($event, $callback, $sort);

        // do something after...
    }

    /**
     * @return void
     */
    public function run()
    {
        if ($this->handleEvents()) {
            echo 'At least one event was caught';
        } else {
            echo 'No event was caught';
        }
    }
}

// Create custom class
class MyEventClass
{
    use MyEventTrait, EventTrait {
        MyEventTrait::on insteadof EventTrait;
        MyEventTrait::run insteadof EventTrait;
    }

    // place some methods...
}

$event = new MyEventClass(['message' => ['text' => 'hello']]);

$event->on(['message.text' => 'hello'], function () {
    echo "👋 Hello!";
});

$event->run();
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

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

Recently: every ~93 days

Total

19

Last Release

1316d ago

Major Versions

1.1.1 → 2.0.12021-10-03

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/19103498?v=4)[chipslays](/maintainers/chipslays)[@chipslays](https://github.com/chipslays)

---

Top Contributors

[![chipslays](https://avatars.githubusercontent.com/u/19103498?v=4)](https://github.com/chipslays "chipslays (40 commits)")

---

Tags

eventevent-drivenevent-emittereventsevent-driver

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[doctrine/event-manager

The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.

6.1k501.1M115](/packages/doctrine-event-manager)[psr/event-dispatcher

Standard interfaces for event handling.

2.3k618.8M865](/packages/psr-event-dispatcher)[laminas/laminas-eventmanager

Trigger and listen to events within a PHP application

1.0k69.8M225](/packages/laminas-laminas-eventmanager)[simshaun/recurr

PHP library for working with recurrence rules

1.6k15.7M40](/packages/simshaun-recurr)[chelout/laravel-relationship-events

Missing relationship events for Laravel

5252.3M17](/packages/chelout-laravel-relationship-events)[tormjens/eventy

The WordPress filter/action system in Laravel

438912.9k16](/packages/tormjens-eventy)

PHPackages © 2026

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