我正在尝试使用zend事件管理器并拥有2个类的附件。然后我尝试触发所有事件并通过每个附加功能。不知何故,我只能收到一个事件而且从未得到其他事件。有人可以指点我正确的方向吗?
// create the event-manager
public static function getEventManager() {
if(!self::$eventManager) {
self::$eventManager = new \Zend_EventManager_EventManager();
}
return self::$eventManager;
}
// attach an event
Item\Plugin::getEventManager()->attach("item.getProvider", function($e) {
$item = $e->getParam("item");
return $this;
});
// attach another event in another class
Item\Plugin::getEventManager()->attach("item.getProvider", function($e) {
$item = $e->getParam("item");
return $this;
});
// get the events attached
$results = self::getEventManager()->trigger("item.getProvider", null, array("item" => $item), function($v) {
return ($v instanceof Item);
});
if($results->stopped())
{
$provider = array();
foreach($results as $result)
{
$provider[] = $result;
}
return $provider;
}
}