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

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

next/event
==========

Event based on the PSR-14 specification

0.2.0(11mo ago)132Apache-2.0PHPPHP ^8.2

Since Oct 31Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/next-laboratory/event)[ Packagist](https://packagist.org/packages/next/event)[ Docs](https://github.com/next-laboratory/event.git)[ RSS](/packages/next-event/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (4)Used By (0)

基于Psr-14的事件
===========

[](#基于psr-14的事件)

如何使用
----

[](#如何使用)

### 创建监听器

[](#创建监听器)

```
use Next\Event\Contract\EventListenerInterface;

class UserStatusListener implements EventListenerInterface
{
    /**
    * 返回该监听器监听的事件
    * @return string[]
    */
    public function listen():array {
        return [
            \App\Events\UserRegistered::class,
        ];
    }

    /**
    * 触发事件后的处理
    * @param object $event
    */
    public function process(object $event): void
    {
        $event->user = false;
    }

    /**
    * 监听器优先级
    * 如果一个事件被多个监听器监听，那么执行顺序可以通过该方法调整
    * 优先级数字越大，优先级越高，越先执行
    * @return int
    */
    public function getPriority(): int
    {
        return 0;
    }
}
```

> 如果你不需要调整优先级，可以直接继承`Next\Event\EventListener`类

### 需要创建一个事件类

[](#需要创建一个事件类)

```
class UserRegistered
{
    public $user;

    public function __construct($user)
    {
        $this->user = $user;
    }
}
```

### 实例化`ListenerProvider`, 使用`addListener`添加监听器

[](#实例化listenerprovider-使用addlistener添加监听器)

```
$listenerProvider = new ListenerProvider();
$listenerProvider->addListener(new UserStatusListener());
```

### 实例化调度器，给构造函数传入`ListenerProvider`实例

[](#实例化调度器给构造函数传入listenerprovider实例)

```
$dispatcher = new \Next\Event\EventDispatcher($listenerProvider);
```

### 事件调度

[](#事件调度)

```
$user = User::find(1);

$event = $dispatcher->dispatch(new UserRegistered($user));
```

可终止事件
-----

[](#可终止事件)

> 事件实现`StoppableEventInterface`接口中的`isPropagationStopped`方法，并且返回true，则不会触发该事件之后的事件

```
class UserRegistered implements StoppableEventInterface
{
    public $user;

    public function __construct($user)
    {
        $this->user = $user;
    }

    public function isPropagationStopped() : bool
    {
        return true;
    }
}
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance60

Regular maintenance activity

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

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

Total

3

Last Release

349d ago

PHP version history (2 changes)0.1PHP ^8.0||^8.1||^8.2

0.1.1PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/ae8591a5d36c52794b3fbc72b1d4199edc62984305386ff65dd97e399137b21f?d=identicon)[chengyao](/maintainers/chengyao)

---

Top Contributors

[![bbuugg](https://avatars.githubusercontent.com/u/64066545?v=4)](https://github.com/bbuugg "bbuugg (5 commits)")

---

Tags

eventseventpsr-14

### Embed Badge

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

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

###  Alternatives

[league/event

Event package

1.6k141.6M184](/packages/league-event)[fig/event-dispatcher-util

Useful utility classes and traits for implementing the PSR events standard

27423.2k19](/packages/fig-event-dispatcher-util)

PHPackages © 2026

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