Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions library/Zend/ModuleManager/Listener/ConfigListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions library/Zend/ModuleManager/ModuleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down