定制 bugadani/event_source 二次开发

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

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

bugadani/event_source

最新稳定版本:1.0

Composer 安装命令:

composer require bugadani/event_source

包简介

A library to create event sources easily

README 文档

README

EventSource is a simple library for PHP 5.4+ to create event source objects.

Usage

EventSource trait

When you wish to make one of your classes an event source, simply use the EventSource trait in them and call the initializer method.

class SomeClass {
    use EventSource\EventSource;

    public function __construct() {
        //initialize defines the events that can be used
        $this->initialize(['fooEvent', 'barEvent']);
    }

    public function someMethod() {
        $this->raise('fooEvent', $someOptionalParameter);
    }
}

You can use the on($eventName, $callback) method to define event handlers which will be notified if the given event is raised.

$someObject = new SomeClass();
$someObject->on('fooEvent', function($someParameter = null) {
    //do something
});

You can also remove event handlers using the remove($eventName, $callback) method.

Event class

Alternatively, you have the option to manually create Event objects that are used by EventSource to manage the event handlers. The Event class has the following methods:

  • on($callback) - register a new callback to handle the event
  • remove($callback) - removes a previously registered callback
  • raise(optional $parameter) - raises the event

One downside is when using the Event class directly is that raise() is a public method, so any outside code may trigger events.

Installation

Using Composer

"require": {
    "bugadani/event_source": "1.*"
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-08