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

Commit

Permalink
Merge branch 'feature/4505' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
24 changes: 21 additions & 3 deletions src/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 src/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
2 changes: 1 addition & 1 deletion test/Listener/ConfigListenerTest.php
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
2 changes: 1 addition & 1 deletion test/Listener/DefaultListenerAggregateTest.php
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

0 comments on commit 7abe866

Please sign in to comment.