定制 gianarb/fast-event-manager 二次开发

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

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

gianarb/fast-event-manager

最新稳定版本:0.1.0

Composer 安装命令:

composer require gianarb/fast-event-manager

包简介

Fast event manager, simples and regex based

README 文档

README

Scrutinizer Code Quality Code Coverage Build Status

PHP event manager based on regex. Trigger events and attach listeners, core feature easy to understand and to extend.

Install

$ composer install gianarb/fast-event-manager

Usage

Getting Started

This is the basic usage

<?php
use FastEventManager\EventManager;

$eventManager = new EventManager();

$eventManager->attach("post-save", function ($assertArg) {
    // DO STUFF
});

$assert = false;
$eventManager->trigger("/post-save/", $assert);

Priority

FastEventManager support priority listeners

$eventManager = new EventManager();

$eventManager->attach("post-save", function ($assertArg) {
    echo "Hi";
}, 100);

$eventManager->attach("post-save", function ($assertArg) {
    echo " dev!";
}, 10);

$eventManager->trigger("/post-save/");

// output "Hi dev!"

Regex

FastEventManager resolve regex, you can trigger more events.

$eventManager = new EventManager();

$eventManager->attach("post-save", function ($assertArg) {
    echo "Hi";
});

$eventManager->attach("pload", function ($assertArg) {
    echo " none!";
});

$eventManager->attach("post-load", function ($assertArg) {
    echo " dev!";
});

$eventManager->trigger("/post-(save|load)/i", $assert);

// output "Hi dev!"

Stop Propagation

At the moment we decided to don't support this feature into the core of FastEventManager because there are a lot of implementation around this feature. This is an example

$eventManager = new EventManager();
$count = 0;
$eventManager->attach("post", function () use (&$count) {
    $count++;
}, 100);
$eventManager->attach("post", function () use (&$count) {
    throw new \Exception();
}, 110);
$eventManager->attach("post", function () use (&$count) {
    $count++;
}, 120);
try {
    $eventManager->trigger("/post/");
} catch (\Exception $exc) {
    // STOP!
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-27