gplanchat/php-event-manager 问题修复 & 功能扩展

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

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

gplanchat/php-event-manager

Composer 安装命令:

composer require gplanchat/php-event-manager

包简介

A basic event manager

README 文档

README

PHP events management library.

Description

The event emitting manager let you implement callback-based event management, for implementing modular code or to make easier class reuse.

Event-based programming is currently available natively into multiple languages and brings some new ways of writing code. Having in mind that this pattern should be used to make code easier to maintain, this pattern should not be used in all cases, especially where other patterns are simpler to implement.

Requirements

  • PHP >= 5.4.0

Unit testing

Run the following command to launch PHPUnit unit tests under the package root directory :

$ phpunit --strict --configuration build/phpunit.xml

Examples

You may find the following code examples useful. Some more examples could be found in the unit tests suite in the tests/ folder.

Basic usage with SharedEventEmitter

$eventEmitter = new SharedEventEmitter();

// Registering a callback for the event 'ready'
$eventEmitter->on(['ready'], function(Event $e) {
    // Your event code comes here...
});

// ...

// Calling the event
$eventEmitter->emit(new Event('ready'));

Passing datas into the Event

$eventEmitter = new SharedEventEmitter();

// Registering a callback for the event 'ready'
$eventEmitter->on(['ready'], function(Event $e) {
    // Your event code comes here...
});

// ...

// Calling the event
$eventEmitter->emit(new Event('ready', [
    'my_object' => new stdClass
]));

Passing datas into the Event, with a defined priority for the callback

$priority = 100;
$callback = function(Event $e) {
    // Your event code comes here...
};

$eventEmitter = new SharedEventEmitter();

// Registering a callback for the event 'ready'
$eventEmitter->on(['ready'], $callback, $priority);

// ...

// Calling the event
$eventEmitter->emit(new Event('ready', [
    'my_object' => new stdClass
]));

Passing datas during event emitting

$eventEmitter = new SharedEventEmitter();

// Registering a callback for the event 'ready'
$eventEmitter->on(['ready'], function(Event $e, $isError, $object) {
    // Your event code comes here...
});

// ...

// Calling the event,
$eventEmitter->emit(new Event('ready'), false, new stdClass);

Implement the EventEmitterInterface interface to build your own event emitters

You may implement this event emitter manager for adding event management to existing frameworks.

class Application
    extends Foo\Framework\ApplicationAbstract
    implements EventEmitterInterface
{
    use EventEmitterTrait;

    public function bootstrap()
    {
        // Bootstrap the instance...

        // emit the 'bootstrap' event, when your method has finished the basic bootstrapping
        $this->emit(new Event('bootstrap', ['application' => $this]));

        return $this;
    }
}

//...

// Registering a callback for the event 'bootstrap'
$eventEmitter->on(['bootstrap'], function(Event $e) {
    // Your event code comes here...
});

//...

// Your caller code looks like this :
$app = new Application();
$app->bootstrap();

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2013-04-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固