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

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

mix/event
=========

Event dispatcher based on PSR-14 standard

v3.0.1(4y ago)12.1k23Apache-2.0PHPPHP &gt;=7.2.0

Since Aug 21Pushed 4y ago2 watchersCompare

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

READMEChangelogDependencies (1)Versions (13)Used By (3)

> OpenMix 出品：[https://openmix.org](https://openmix.org/mix-php)

Mix Event
=========

[](#mix-event)

Event dispatcher based on PSR-14 standard

基于 PSR-14 标准的事件调度库

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

[](#installation)

```
composer require mix/event

```

定义一个事件
------

[](#定义一个事件)

事件可以为任意类，我们以 SQL 执行事件调度来举例

```
class DatabaseEvent
{
    public $time = 0;
    public $sql = '';
    public $bindings = [];
}
```

定义一个监听器
-------

[](#定义一个监听器)

监听器是用户编写处理事件逻辑代码的地方，`events` 方法返回一个要监听的事件类的数组，当这些事件触发时，会调用 `process` 方法

```
class DatabaseListener implements Mix\Event\ListenerInterface
{

    public function events(): array
    {
        // 要监听的事件数组，可监听多个事件
        return [
            DatabaseEvent::class,
        ];
    }

    public function process(object $event): void
    {
        // 事件触发后，会执行该方法
    }

}
```

创建调度器
-----

[](#创建调度器)

创建调度器，并传入监听器，可传入多个

```
$dispatcher = new Mix\Event\EventDispatcher(new DatabaseListener());
```

触发事件
----

[](#触发事件)

在事件产生的位置触发事件，当后面需要对该事件扩展业务逻辑时，只需在监听器中增加代码即可，达到不污染正常业务流程的目的

```
$event = new DatabaseEvent();
$event->time = 10;
$event->sql = 'select * from users';
$dispatcher->dispatch($event);
```

License
-------

[](#license)

Apache License Version 2.0,

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 88.9% 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 ~63 days

Recently: every ~109 days

Total

12

Last Release

1759d ago

Major Versions

v2.2.14 → v3.0.12021-07-21

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16074765?v=4)[LIU JIAN](/maintainers/onanying)[@onanying](https://github.com/onanying)

---

Top Contributors

[![onanying](https://avatars.githubusercontent.com/u/16074765?v=4)](https://github.com/onanying "onanying (8 commits)")[![yupeng2015](https://avatars.githubusercontent.com/u/10594818?v=4)](https://github.com/yupeng2015 "yupeng2015 (1 commits)")

---

Tags

eventevent-dispatchermixpsreventdispatchmix

### Embed Badge

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

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

###  Alternatives

[league/event

Event package

1.6k141.6M184](/packages/league-event)[zumba/symbiosis

Symbiosis, event structure for bootstrapping plugins.

1360.4k1](/packages/zumba-symbiosis)

PHPackages © 2026

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