diff --git a/library/Zend/ModuleManager/Listener/ConfigListener.php b/library/Zend/ModuleManager/Listener/ConfigListener.php index f19729b3022..8d2e9d4dd19 100644 --- a/library/Zend/ModuleManager/Listener/ConfigListener.php +++ b/library/Zend/ModuleManager/Listener/ConfigListener.php @@ -89,8 +89,8 @@ public function attach(EventManagerInterface $events) } $this->callbacks[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULE, array($this, 'onLoadModule')); - $this->callbacks[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULES, array($this, 'onLoadModulesPost'), -1000); - + $this->callbacks[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULES, array($this, 'onLoadModules'), -1000); + $this->callbacks[] = $events->attach(ModuleEvent::EVENT_MERGE_CONFIG, array($this, 'onMergeConfig'), 1000); return $this; } @@ -137,7 +137,7 @@ public function onLoadModule(ModuleEvent $e) * @param ModuleEvent $e * @return ConfigListener */ - public function onLoadModulesPost(ModuleEvent $e) + public function onMergeConfig(ModuleEvent $e) { // Load the config files foreach ($this->paths as $path) { @@ -150,6 +150,24 @@ public function onLoadModulesPost(ModuleEvent $e) $this->mergedConfig = ArrayUtils::merge($this->mergedConfig, $config); } + return $this; + } + + /** + * Optionally cache merged config + * + * This is only attached if config is not cached. + * + * @param ModuleEvent $e + * @return ConfigListener + */ + public function onLoadModules(ModuleEvent $e) + { + + // Trigger MERGE_CONFIG event. This is a hook to allow the merged application config to be + // modified before it is cached (In particular, allows the removal of config keys) + $e->getTarget()->getEventManager()->trigger(ModuleEvent::EVENT_MERGE_CONFIG, $e->getTarget(), $e); + // If enabled, update the config cache if ( $this->getOptions()->getConfigCacheEnabled() diff --git a/library/Zend/ModuleManager/ModuleEvent.php b/library/Zend/ModuleManager/ModuleEvent.php index c81e773d55c..e29dd8e2834 100644 --- a/library/Zend/ModuleManager/ModuleEvent.php +++ b/library/Zend/ModuleManager/ModuleEvent.php @@ -20,6 +20,7 @@ class ModuleEvent extends Event /** * Module events triggered by eventmanager */ + CONST EVENT_MERGE_CONFIG = 'mergeConfig'; CONST EVENT_LOAD_MODULES = 'loadModules'; CONST EVENT_LOAD_MODULE_RESOLVE = 'loadModule.resolve'; CONST EVENT_LOAD_MODULE = 'loadModule'; diff --git a/tests/ZendTest/ModuleManager/Listener/ConfigListenerTest.php b/tests/ZendTest/ModuleManager/Listener/ConfigListenerTest.php index f171d1609b5..d92a3544423 100644 --- a/tests/ZendTest/ModuleManager/Listener/ConfigListenerTest.php +++ b/tests/ZendTest/ModuleManager/Listener/ConfigListenerTest.php @@ -378,7 +378,7 @@ public function testConfigListenerFunctionsAsAggregateListener() $this->assertEquals(2, count($moduleManager->getEventManager()->getEvents())); $configListener->attach($moduleManager->getEventManager()); - $this->assertEquals(3, count($moduleManager->getEventManager()->getEvents())); + $this->assertEquals(4, count($moduleManager->getEventManager()->getEvents())); $configListener->detach($moduleManager->getEventManager()); $this->assertEquals(2, count($moduleManager->getEventManager()->getEvents())); diff --git a/tests/ZendTest/ModuleManager/Listener/DefaultListenerAggregateTest.php b/tests/ZendTest/ModuleManager/Listener/DefaultListenerAggregateTest.php index 79ec16bdda1..39f4dcf38e6 100644 --- a/tests/ZendTest/ModuleManager/Listener/DefaultListenerAggregateTest.php +++ b/tests/ZendTest/ModuleManager/Listener/DefaultListenerAggregateTest.php @@ -109,7 +109,7 @@ public function testDefaultListenerAggregateCanDetachItself() $this->assertEquals(1, count($moduleManager->getEventManager()->getEvents())); $listenerAggregate->attach($moduleManager->getEventManager()); - $this->assertEquals(3, count($moduleManager->getEventManager()->getEvents())); + $this->assertEquals(4, count($moduleManager->getEventManager()->getEvents())); $listenerAggregate->detach($moduleManager->getEventManager()); $this->assertEquals(1, count($moduleManager->getEventManager()->getEvents()));