atphp/event
最新稳定版本:v0.1.4
Composer 安装命令:
composer require atphp/event
包简介
Wrapper for Symfony EventDispatcher component to provide more functionality.
README 文档
README
Wrapper for Symfony Event Dispatcher to provide more functionality.
<?php use Symfony\Component\EventDispatcher\Event; use AndTruong\Common\EventAware; class MyClass extends EventAware { public function myEventAwareMethod() { $this->dispatch('my.event.before'); $event = new Event(); $this->dispatch('my.event.after', $event); // or simpler $this->trigger('my.other.event', $this, ['param 1', 'param 2']); } } // Class usage $myobj = new MyClass(); $myobj->getDispatcher()->addListener('my.event.before', function(\AndyTruong\Common\Event $e) { $e->getTarget(); // instance of MyClass $e->getParams(); // ['param 1', 'param 2'] }); $myobj->myEventAwareMethod();
Result collecting
In real projects, we often collect results from external code. It can be done easily like this:
<?php $myobj = new MyClass(); $myobj->getDispatcher()->addListener('my.results.collecting.event', function(\AndyTruong\Common\Event $e) { $e->addResult("Hello there!"); }); $myobj->collectResults('my.results.collecting.event'); // ["Hello there!"] // to validate input $myobj->collectResults('my.results.collecting.event', null, null, [ function($input) { if (!is_string($input)) { throw new \Exception('Input must be string!'); } } ]); // ["Hello there!"]
统计信息
- 总下载量: 198
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-19