zendframework/zf2 — pull request #660 by EvanDotPro (2011-12-09 17:39:55+00:00)
Title: Module manager event implementation improvements

## THIS PR BREAKS BC! SEE BELOW.

### Included in this PR:

* The init.post event has been renamed to 'loadModules.post'
* New event addded to module manager: 'loadModules.pre'
* New event addded to module manager: 'loadModule.resolve' -- You can attach events to this and provide alternative ways of loading and resolving modules (or even supplement the existing one)
* Module resolving has been moved from the module manager to the new `ModuleResolverListener` which listens to 'loadModule.resolve'
* ConfigListener can now be attached as an aggregate listener
* All 'default listener' logic has been removed from the module manager
* `DefaultListenerAggregate` added which aggregates default listeners (init, config, autoloader), and attaches the module autoloader to the 'loadModules.pre' event.
* All unit tests updated: 100% code coverage.

### BC breaks explained:

#### index.php

You need to update index.php for the API changes in the module manager / listeners. Here is an example updated `index.php`:

array()));

$appConfig = include 'config/application.config.php';

$moduleManager = new Zend\Module\Manager($appConfig['modules']);
$listenerOptions = new Zend\Module\Listener\ListenerOptions($appConfig['module_listener_options']);
$defaultListeners = new Zend\Module\Listener\DefaultListenerAggregate($listenerOptions);

$defaultListeners->getConfigListener()->addConfigGlobPath('config/autoload/*.config.php');
$moduleManager->events()->attachAggregate($defaultListeners);
$moduleManager->loadModules();

// Create application, bootstrap, and run
$bootstrap = new Zend\Mvc\Bootstrap($defaultListeners->getConfigListener()->getMergedConfig());
$application = new Zend\Mvc\Application;
$bootstrap->bootstrap($application);
$application->run()->send();

#### application.config.php

In `application.config.php`, you will need to move the 'module_paths' array into the 'module_listener_options' array like this:

array(
'Application',
),
'module_listener_options' => array(
'config_cache_enabled' => false,
'cache_dir' => realpath(dirname(__DIR__) . '/data/cache'),
'module_paths' => array(
realpath(dirname(__DIR__) . '/module'),
realpath(dirname(__DIR__) . '/vendor'),
),
),
);

#### In your modules:

* Anywhere in your `Module.php` you attach to the 'init.post' event, you will need to change it to 'loadModules.post'.
* In your 'init.post' (now 'loadModules.post') listener(s), if you retrieve the config via `$e->getTarget()->getMergedConfig();`, you will need to change that to `$e->getConfigListener()->getMergedConfig();`. If your 'loadModules.post' listener has a priority set which is > 9000, it will not have access to the config listener (nor the merged config).