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

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

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

h2sf/events

最新稳定版本:0.4.3.1

Composer 安装命令:

composer require h2sf/events

包简介

description

README 文档

README

Event manager

IMPORTANT - Consumer methods / callables require a type. This type is used to figure out on what event should consumer be executed. Missing type will throw Exception. If you want to execute for any Event - use EventInterface. EventManager uses instanceof to check if event can be used for a consumer

$logger = new BasicLogger(__DIR__.'/logs.log');
// Initilize new instance
// Logger is required to log uncaught exceptions from each consumer. 
// One consumer's exception doesn't have to stop others
$eventManager = new EventManager($logger);

// Optional, set by default
// This will cause execution of consumers at the moment of queueEvent()
$eventManager->setConsumeImmediately(true);

// If you want...
$eventManager->setThrowOnFirstConsumerError(true);
// It will use logger first and then throw

// Anonymous classes can be registered - as well as just objects implementing the ConsumerInterface
$eventManager->addListener(new class implements ConsumerInterface {
    public function consumeEvent(EventInterface $event)
    {
        echo "[ANY EVENT] ";
    }
});

// Callables can be registered
$eventManager->addListener(function(EventInitialized $event) use($bootstrap) {
    echo "[INITIALIZED, running at {$bootstrap->getTargetTPS()} TPS]\n";
});

// And you post / execute consumers
$eventManager->queueEvent(new \Siarko\CliBootstrap\Events\EventInitialized());

// Also, if setConsumeImmediately(false), consumers won't be executed.
// Events will be queued and then consumers will execute at once with
$eventManager->consumeEvents();

// If you want to postpone execution of a selected event, use
$eventManager->queueEvent(new \Siarko\CliBootstrap\Events\EventInitialized(), postpone: true);
//It will execute the consumers for this event either with next normal event execution of with
$eventManager->consumeEvents();

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: proprietary
  • 更新时间: 2024-07-30