定制 ez-php/events 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ez-php/events

Composer 安装命令:

composer require ez-php/events

包简介

Event dispatcher module for the ez-php framework — lightweight publish/subscribe event system

README 文档

README

Event dispatcher module for the ez-php framework — synchronous event bus with listener priority, wildcard patterns, propagation control, and async dispatch via queue.

CI

Requirements

  • PHP 8.5+
  • ez-php/framework 0.*

Installation

composer require ez-php/events

Setup

Register the service provider:

$app->register(\EzPhp\Events\EventServiceProvider::class);

Usage

Defining an event

use EzPhp\Events\EventInterface;

class UserCreated implements EventInterface
{
    public function __construct(public readonly int $userId) {}
}

Listening and dispatching

use EzPhp\Events\Event;

// Register a closure listener
Event::listen(UserCreated::class, function (UserCreated $event): void {
    // send welcome email
});

// Register a class-based listener
Event::listen(UserCreated::class, new SendWelcomeEmail());

// Dispatch
Event::dispatch(new UserCreated(42));

Listener priority

Higher priority fires first. Listeners with equal priority fire in registration order.

Event::listen(UserCreated::class, new LogUserCreation(), priority: 10);
Event::listen(UserCreated::class, new SendWelcomeEmail(), priority: 5);
// LogUserCreation fires before SendWelcomeEmail

Wildcard patterns

Use * and ? (fnmatch-style) to listen to multiple event classes at once:

Event::listen('App\Events\Order*', function (EventInterface $event): void {
    // fires for OrderPlaced, OrderShipped, OrderDelivered, ...
});

Stopping propagation

Implement StoppableEventInterface to stop further listeners mid-dispatch:

use EzPhp\Events\StoppableEventInterface;

class UserCreated implements StoppableEventInterface
{
    private bool $stopped = false;

    public function isPropagationStopped(): bool { return $this->stopped; }
    public function stopPropagation(): void { $this->stopped = true; }
}

A Closure listener can also stop propagation by returning false.

Async dispatch

Pass async: true to push the event onto a queue instead of running listeners immediately (requires a QueueInterface configured on the dispatcher):

Event::dispatch(new UserCreated(42), async: true);

When no queue is configured, async: true falls through to synchronous dispatch.

Config-based listener registration

Declare listeners in config/events.phpEventServiceProvider registers them automatically during boot():

return [
    'listeners' => [
        UserCreated::class => [
            SendWelcomeEmail::class,
            LogUserCreation::class,
        ],
    ],
];

Each listener class is resolved through the container (supports autowiring). Additional listeners can still be registered imperatively in any service provider that boots after EventServiceProvider:

Event::listen(OrderPlaced::class, new SendOrderConfirmation());

Class-based listeners

use EzPhp\Events\ListenerInterface;

class SendWelcomeEmail implements ListenerInterface
{
    public function handle(EventInterface $event): void
    {
        assert($event instanceof UserCreated);
        // send the email
    }
}

Classes

Class Description
EventInterface Marker interface all dispatchable events must implement
ListenerInterface Contract for class-based listeners: handle(EventInterface): void
StoppableEventInterface Extends EventInterface; events can call stopPropagation() to halt the dispatch chain
EventDispatcher Synchronous bus with priority ordering, wildcard matching, propagation control, and async queue support
Event Static façade backed by a managed EventDispatcher singleton
AsyncEventJob JobInterface implementation that wraps an event for deferred queue-based dispatch
EventServiceProvider Binds EventDispatcher, wires static façade, auto-registers config/events.php listeners

License

MIT — Andreas Uretschnig

ez-php/events 适用场景与选型建议

ez-php/events 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 248 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「event-dispatcher」 「php」 「events」 「pub-sub」 「ez-php」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ez-php/events 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ez-php/events 我们能提供哪些服务?
定制开发 / 二次开发

基于 ez-php/events 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 248
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 25
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-14