shieldon/event-dispatcher 问题修复 & 功能扩展

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

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

shieldon/event-dispatcher

最新稳定版本:1.0.0

Composer 安装命令:

composer require shieldon/event-dispatcher

包简介

Event dispatcher for PHP.

README 文档

README

Build Status codecov License: MIT

This package is designed as a part of Shieldon Firewall 2. You can also use it on your projects as well.

Installation

Use PHP Composer:

composer require shieldon/event-dispatcher

Or, download it and include the Shieldon autoloader.

require 'autoload.php';

Usage

Add a Listener

/**  * @param string $name The name of an event.  * @param string|array $func Callable function or class.  * @param int $priority The execution priority.  *   * @return bool  */ \Shieldon\Event\Event::addLister(string $name, $func, int $priority = 10): bool

Please note, the priority must be unique. This method returns true when add a listener, false when the prirotiy has been taken by another listener.

Dispatch

/**  * @param string $name The name of an event.  * @param array $args The arguments.  *   * @return mixed  */ \Shieldon\Event\Event::doDispatch(string $name, array $args = []): mixed

Return the filtered result, it's similar to WordPress' filter. You can ignore the return if you don't need that.

Example

Closure

Add a listener.

\Shieldon\Event\Event::addListener('test_1', function() { echo 'This is a closure function call.'; });

Dispatch.

$result = \Shieldon\Event\Event::doDispatch('test_1');

Function

Function for listener.

function test_event_disptcher() { echo 'This is a function call.'; }

Add a listener.

\Shieldon\Event\Event::addListener('test_2', 'test_event_disptcher');

Dispatch.

$result = \Shieldon\Event\Event::doDispatch('test_2');

Class

Add a listener.

$example = new Example(); \Shieldon\Event\Event::addListener('test_3', [$example, 'example1']);

Dispatch.

$result = \Shieldon\Event\Event::doDispatch('test_3');

Hope this helps.

Author

License

MIT

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固