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();
gplanchat/php-event-manager 适用场景与选型建议
gplanchat/php-event-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 299 次下载、GitHub Stars 达 5, 最近一次更新时间为 2013 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 gplanchat/php-event-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gplanchat/php-event-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 299
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 6
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2013-04-02