共生体 / 调度器
v1.0.2
2024-06-28 13:48 UTC
Requires
- php: ^8.2
- symbiont/support-forward-call: ^1.0
Requires (Dev)
- mockery/mockery: ^1.6
- phpunit/phpunit: ^11.1
README
简单事件调度器
此包正在开发中!
要求
php 8.2
安装
composer require symbiont/dispatcher
使用
使用 EventDispatcher
和 Dispatcher
。
use Symbiont\Dispatcher\{Dispatcher, EventDispatcher};
// global event dispatcher
EventDispatcher::register('test', function() {
return 'test';
});
EventDispatcher::once('test', function() {
return 'once';
})
EventDispatcher::dispatch('test');
// local event dispatcher
$dispatcher = new Dispatcher;
$dispatcher->register('test', function() {
return 'test';
});
$dispatcher->once('test', function() {
return 'once';
});
$dispatcher->dispatch('test');
使用 Callbackable
和 DispatchesEvent
特性实现回调事件调度器。
use Symbiont\Dispatcher\Contracts\Callbackable;
use Symbiont\Dispatcher\Concerns\DispatchesEvent;
class Awesome implements Callbackable {
use DispatchesEvent;
public function load() {
$this->trigger('beforeLoad');
// something to load ..
$this->trigger('afterLoad');
}
}
$awesome = new Awesome;
$awesome->on('afterLoad', function() {
// something to do after load ..
});
$awesome->load();
文档
此文档仅记录此包的技术使用,几乎没有文本。
测试
composer test