Fixes to enable and enforce SharedEventManager instance
authorMatthew Weier O'Phinney <matthew@zend.com>
Mon, 23 Apr 2012 19:40:13 +0000 (14:40 -0500)
committerMatthew Weier O'Phinney <matthew@zend.com>
Mon, 23 Apr 2012 19:40:13 +0000 (14:40 -0500)
- Instead of using StaticEventManager, pull shared collection for event manager
  in module manager
- Instantiate and injected SharedEventManager in index.php (we can refine and
  abstract this later)

module/Application/Module.php
public/index.php

index d85f6cf..a540a11 100644 (file)
@@ -10,8 +10,9 @@ class Module implements AutoloaderProvider
 {
     public function init(Manager $moduleManager)
     {
-        $events = StaticEventManager::getInstance();
-        $events->attach('bootstrap', 'bootstrap', array($this, 'initializeView'), 100);
+        $events       = $moduleManager->events();
+        $sharedEvents = $events->getSharedCollections();
+        $sharedEvents->attach('bootstrap', 'bootstrap', array($this, 'initializeView'), 100);
     }
 
     public function getAutoloaderConfig()
index 354a083..418b63b 100644 (file)
@@ -5,17 +5,21 @@ Zend\Loader\AutoloaderFactory::factory();
 
 $appConfig = include 'config/application.config.php';
 
+$sharedEvents     = new Zend\EventManager\SharedEventManager();
 $listenerOptions  = new Zend\Module\Listener\ListenerOptions($appConfig['module_listener_options']);
 $defaultListeners = new Zend\Module\Listener\DefaultListenerAggregate($listenerOptions);
 $defaultListeners->getConfigListener()->addConfigGlobPath("config/autoload/{,*.}{global,local}.config.php");
     
 
 $moduleManager = new Zend\Module\Manager($appConfig['modules']);
-$moduleManager->events()->attachAggregate($defaultListeners);
+$events        = $moduleManager->events();
+$events->setSharedCollections($sharedEvents);
+$events->attach($defaultListeners);
 $moduleManager->loadModules();
 
 // Create application, bootstrap, and run
 $bootstrap   = new Zend\Mvc\Bootstrap($defaultListeners->getConfigListener()->getMergedConfig());
+$bootstrap->events()->setSharedCollections($sharedEvents);
 $application = new Zend\Mvc\Application;
 $bootstrap->bootstrap($application);
 $application->run()->send();