selvinortiz / gossip
适用于PHP 5.4+的轻量级事件广播库
v1.0.0
2016-06-23 17:13 UTC
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: ^4.8
This package is auto-updated.
Last update: 2024-09-21 19:21:54 UTC
README
描述
Gossip 是由 Selvin Ortiz 编写的一个小巧的事件广播库
需求
- PHP 5.4+
- Composer 和 selvinortiz/gossip
安装
composer require selvinortiz/gossip
测试
sh spec.sh
用法
事件广播是一种说法,即 Gossip 允许您注册您的 响应者 以 监听 特定事件,当该事件被 低声说出 时,它可以做出响应。
use SelvinOrtiz\Gossip\Gossip; class App { public function init() { Gossip::instance()->whisper(new Event('app.init')); } public function end() { Gossip::instance()->whisper(new Event('app.end', [$this])); } public function log($message) { // Log a $message to db or file system } } // Called when app.init is whisper()ed Gossip::instance()->listen('app.init', function (Event &$event) { // Bootstrap third party code, initialize services, etc. }); // Called only the first time app.end is whisper()ed Gossip::instance()->listenOnce('app.end', function (Event &$event, $app) { // Close db connections, destroy sessions, etc. $app->log('Application is ending...'); });
API
API参考即将推出...
贡献
Gossip 希望对 初次贡献者 友好。只需按照以下步骤操作,并在过程中有任何问题,请随时联系。
- 分叉它!
- 创建您的错误修复或功能分支
- 提交并推送您的更改
- 提交拉取请求
许可
Gossip 是开源软件,许可协议为 MIT 许可