Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Module manager event implementation improvements #660

Merged

Conversation

EvanDotPro
Copy link
Member

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:

<?php
chdir(dirname(__DIR__));
require_once 'vendor/ZendFramework/library/Zend/Loader/AutoloaderFactory.php';
Zend\Loader\AutoloaderFactory::factory(array('Zend\Loader\StandardAutoloader' => 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:

<?php
return array(
    'modules' => 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).

- s/init.post/loadModules.post/
- add loadModules.pre
- Module manager can take an EventManager via its constructor
- Remove notion of default listeners from module manager
- Add DefaultListenerAggregate which has all the default listeners
- Add ModuleResolverListener for more dynamic resolution of module classes
- Ran: find library/Zend/Module -type f -name '*.php' | xargs sed -i 's/[[:space:]]*$//'
- Refactored long lines to be <= 120 chars
- Fixed a couple of bugs found while writing tests
- 100% coverage for Zend\Module
- Now covers all new aggregate listener stuff
@akrabat akrabat merged commit 5ba29ef into zendframework:master Dec 9, 2011
@weierophinney
Copy link
Member

Very excited to see this, Evan -- thanks for taking the ideas Ralph and I threw over the fence yesterday and making them a reality!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants