helmich/flow-eventbroker
Composer 安装命令:
composer require helmich/flow-eventbroker
包简介
TYPO3 Flow package containing an event dispatching mechanism
README 文档
README
A simple event dispatching library for TYPO3 Flow.
Installation
The package is available on Packagist. Use the following setup in your composer manifest:
{
"require": {
"helmich/flow-eventbroker": "*"
}
}
Examples
Publishing events
Events are regular methods that are tagged with an @Event\Event annotation:
<?php
namespace My\Example;
use Helmich\EventBroker\Annotations as Event;
class Emitter {
public function doSomething() {
// ...
$this->publishSomeEvent(new SomeEvent("foo"));
}
/**
* @Event\Event
*/
protected function publishSomeEvent(SomeEvent $event) {
}
}
Subscribing to events
Listeners are also regular methods, that are tagged with an @Event\Listener annotation.
The event class to listen for is specified as parameter within the annotation.
<?php
namespace My\Example;
use Helmich\EventBroker\Annotations as Event;
class Listener {
/**
* @Event\Listener("My\Example\SomeEvent")
*/
public function myListener(SomeEvent $event) {
}
}
Synchronous and asynchronous events
By defaults, listeners will be called asynchronously. In the default implementation, events will be queued and dispatched in an event loop at the end of the main application run (other, later implementations might do this completely asynchronously by dispatching events to another process).
You can explicitly declare listeners to be processed synchronously (when the event is published)
by using the "sync" tag in the @Event\Listener annotation:
<?php
namespace My\Example;
use Helmich\EventBroker\Annotations as Event;
class Listener {
/**
* @Event\Listener("My\Example\SomeEvent", sync=TRUE)
*/
public function myListener(SomeEvent $event) { }
}
To-Do
- Add unit test coverage
- Provide mechanisms for asynchronous event processing
统计信息
- 总下载量: 40
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-09-28