I'm getting some weird behaviour with the EventManager and SharedEventManager
when used in the Application module vs other modules.
Application Module:
public function onBootstrap(MvcEvent $e)
{
//$e->getApplication()->getServiceManager()->get('translator');
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$eventManager->attach(MvcEvent::EVENT_DISPATCH, function ($event){
echo 'event listener from application module called' . PHP_EOL;
});
$sharedEvents = $eventManager->getSharedManager();
$sharedEvents->attach(__NAMESPACE__, MvcEvent::EVENT_DISPATCH, function
($event){
echo 'shared event listener from application module called'.
PHP_EOL;
});
}
My Module:
public function onBootstrap(\Zend\EventManager\EventInterface $e)
{
$eventManager = $e->getApplication()->getEventManager();
$sharedEvents = $eventManager-> getSharedManager();
$eventManager->attach(MvcEvent::EVENT_DISPATCH, function ($event){
echo 'event listener from my module called'.PHP_EOL;
});
$sharedEvents->attach(__NAMESPACE__, MvcEvent::EVENT_DISPATCH, function
($event){
echo 'shared event listener from my module called'.PHP_EOL;
});
}
outputs:
shared event listener from my module called
event listener from application module called
event listener from my module called
Can someone explain why the shared event listener attached via the Application
module never gets called?
Secondary to this, I've seen some examples attach listeners to the shared
manager, and others attach them to the event manager. When do I use one instead
of the other?
Cheers,
David
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]