Merge remote-tracking branch 'weierophinney/hotfix/event-manager-shared'
[zf2.biz/application_blanche.git] / public / index.php
index 9c388be..6c1ddb7 100644 (file)
@@ -1,30 +1,25 @@
 <?php
-// Define application environment
-defined('APPLICATION_ENV')
-    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
+chdir(dirname(__DIR__));
+require_once (getenv('ZF2_PATH') ?: 'vendor/ZendFramework/library') . '/Zend/Loader/AutoloaderFactory.php';
+Zend\Loader\AutoloaderFactory::factory();
 
-// Ensure ZF is on the include path
-set_include_path(implode(PATH_SEPARATOR, array(
-    realpath(__DIR__ . '/../library'),
-    realpath(__DIR__ . '/../library/ZendFramework/library'),
-    get_include_path(),
-)));
+$appConfig = include 'config/application.config.php';
 
-require_once 'Zend/Loader/AutoloaderFactory.php';
-Zend\Loader\AutoloaderFactory::factory(array('Zend\Loader\StandardAutoloader' => array()));
-
-$appConfig = include __DIR__ . '/../configs/application.config.php';
-
-$moduleLoader = new Zend\Loader\ModuleAutoloader($appConfig['module_paths']);
-$moduleLoader->register();
+$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/*.php");
+    
 
 $moduleManager = new Zend\Module\Manager($appConfig['modules']);
-$listenerOptions = new Zend\Module\Listener\ListenerOptions($appConfig['module_listener_options']);
-$moduleManager->setDefaultListenerOptions($listenerOptions);
+$events        = $moduleManager->events();
+$events->setSharedCollections($sharedEvents);
+$events->attach($defaultListeners);
 $moduleManager->loadModules();
 
 // Create application, bootstrap, and run
-$bootstrap      = new Zend\Mvc\Bootstrap($moduleManager->getMergedConfig());
-$application    = new Zend\Mvc\Application;
+$bootstrap   = new Zend\Mvc\Bootstrap($defaultListeners->getConfigListener()->getMergedConfig());
+$bootstrap->events()->setSharedCollections($sharedEvents);
+$application = new Zend\Mvc\Application;
 $bootstrap->bootstrap($application);
 $application->run()->send();