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.
Closed
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
20 changes: 17 additions & 3 deletions library/Zend/ModuleManager/ModuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,24 @@ public function loadModule($module)
return $this->loadedModules[$moduleName];
}

$event = ($this->loadFinished === false) ? clone $this->getEvent() : $this->getEvent();
/*
* Keep track of nested module loading using the $loadFinished
* property.
*
* Increment the value for each loadModule() call and then decrement
* once the loading process is complete.
*
* To load a module, we clone the event if we are inside a nested
* loadModule() call, and use the original event otherwise.
*/
if (!isset($this->loadFinished)) {
$this->loadFinished = 0;
}

$event = ($this->loadFinished > 0) ? clone $this->getEvent() : $this->getEvent();
$event->setModuleName($moduleName);

$this->loadFinished = false;
$this->loadFinished++;

if (!is_object($module)) {
$module = $this->loadModuleByName($event);
Expand All @@ -153,7 +167,7 @@ public function loadModule($module)
$this->loadedModules[$moduleName] = $module;
$this->getEventManager()->trigger(ModuleEvent::EVENT_LOAD_MODULE, $this, $event);

$this->loadFinished = true;
$this->loadFinished--;

return $module;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/ZendTest/ModuleManager/ModuleManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ public function testCanLoadModuleDuringTheLoadModuleEvent()
$config = $configListener->getMergedConfig();
$this->assertTrue(isset($config['loaded']));
$this->assertSame('oh, yeah baby!', $config['loaded']);

$this->assertTrue(isset($config['baz']));
$this->assertSame('bar', $config['baz']);
}

public function testModuleIsMarkedAsLoadedWhenLoadModuleEventIsTriggered()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Module
public function init($moduleManager)
{
$moduleManager->loadModule('BarModule');
$moduleManager->loadModule('BazModule');
}

public function getConfig()
Expand Down