comphp/events 问题修复 & 功能扩展

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

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

comphp/events

最新稳定版本:v0.2

Composer 安装命令:

composer require comphp/events

包简介

A lightweight, modular event dispatcher with PSR-14 compatibility and an object-oriented approach for registering and triggering events.

README 文档

README

A lightweight, PSR-14 compatible event dispatching library designed for simplicity and efficiency. It provides a global yet replaceable event dispatcher, supports prioritized listeners, and allows flexible event handling.

Features

  • PSR-14 Compatible: Implements the standard event dispatcher interface.
  • Simple Event Registration: Easily register and dispatch events.
  • Prioritized Listeners: Control execution order with priority levels.
  • Global or Dependency Injected: Use globally or inject as needed.
  • Supports Stoppable Events: Halt propagation when necessary.

Installation

Install via Composer:

composer require comphp/events

Usage

Create and dispatch events using the EventDispatcher.

<?php
require 'vendor/autoload.php';

use Neuron\Events\EventDispatcher;
use Neuron\Events\AbstractEvent;

// Define an event
class UserRegisteredEvent extends AbstractEvent
{
    public function __construct(private string $username)
    {
        parent::__construct(['username' => $username]);
    }
}

// Initialize the dispatcher
$dispatcher = new EventDispatcher();

// Register a listener
$dispatcher->listen(UserRegisteredEvent::class, function (UserRegisteredEvent $event) {
    echo "User registered: " . $event->getPayload()['username'] . "\n";
});

// Dispatch the event
$dispatcher->dispatch(new UserRegisteredEvent('Tim'));

Examples

Additional example scripts are provided in the examples/ directory, demonstrating different use cases of event dispatching.

Changelog

See CHANGELOG.md for a record of changes.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details on how to help out.

Code of Conduct

This project is released under a Code of Conduct. Please review CODE_OF_CONDUCT.md for details.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-17