iceylan/eventor 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

iceylan/eventor

最新稳定版本:v1.0.1

Composer 安装命令:

composer require iceylan/eventor

包简介

Simple event emitter and dispatcher for PHP

README 文档

README

This is a lightweight event handling system for PHP classes via Trait.

Eventor provides a simple event-driven API to any PHP class without forcing inheritance. Attach event listeners, trigger them, propagate results, and handle listeners with priority and once-only options.

🚀 Installation

composer require iceylan/eventor

✨ Features

  • Add event-driven behavior to any class via a trait
  • Support for on, once, off, trigger
  • Listener priority system
  • Stop event propagation
  • Collect listener return values
  • Minimal and flexible

🔥 Usage

use Iceylan\Eventor\ShouldDispatchEvents;
use Iceylan\Eventor\HasEvents;

class User implements ShouldDispatchEvents
{
    use HasEvents;
}

// Example
$user = new User();

$user->on( 'registered', function()
{
    return 'Sending welcome email.';
});

$user->on( 'registered', function()
{
    return 'Logging registration.';
}, priority: 10 );
// Higher priority, runs first

$results = $user->trigger( 'registered' );

print_r($results);

Output:

[
    'Logging registration.',
    'Sending welcome email.'
]

🛠 Advanced Usage

You can alias trait methods when using the trait, allowing you to customize your API surface:

use Iceylan\Eventor\HasEvents;

class Order
{
    use HasEvents {
        on as public addHook;
        off as public removeHook;
        trigger as public runHook;
    }
}

$order = new Order();

$order->addHook( 'something.happened', function()
{
    echo "something happened";
});

$order->runHook( 'something.happened' );

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-26