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

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

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

maer/events

最新稳定版本:0.1.0

Composer 安装命令:

composer require maer/events

包简介

Small package to handle events

README 文档

README

Need events? Here you go! No fuzz, no overcomplicated instantiation or bloated classes.

Install

Git clone or use composer to download the package with the following command:

composer require maer/events 0.*

Usage

Include composers autoloader or include the files in the src/ folder manually. (start with the file EventInterface.php)

Create a new instance

$event = new Maer\Events\Event();

Add a listener

$event->addListener('start_something', 'some-id', function($name) {
    echo "Coolest ever: {$name}";
});

Trigger/Emit an event

$response = $event->emit('start_something', ['Chuck Norris']);

// Echoes: Coolest ever: Chuck Norris

Remove a listener

$event->removeListener('start_something', 'some-id');

Facade/Factory

If you don't want to store the Event class instance yourself, you can use the combined Facade/Factory class.

Use it as a Factory

This will always return the same instance

$event = Maer\Events\EventFacade::getInstance();

To use it as a Facade

This will use the same instance as getInstance() returns so you can combine the two

Maer\Events\EventFacade::addListener(...);

Maer\Events\EventFacade::removeListener(...);

$response = Maer\Events\EventFacade::emit(...);

//... and any other method available in the Event class

More...

Above is the basic usage but there is more... I'll update this guide soon.

统计信息

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

GitHub 信息

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

其他信息

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