Skip to content

Commit

Permalink
Merge pull request zendframework#1983 from coss/hotfix/module-load-du…
Browse files Browse the repository at this point in the history
…ring-trigger

Module load disruption bugfix
  • Loading branch information
EvanDotPro committed Jul 25, 2012
2 parents 2d5a19e + 88eed43 commit edb5f72
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
12 changes: 11 additions & 1 deletion library/Zend/ModuleManager/ModuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class ModuleManager implements ModuleManagerInterface
*/
protected $event;

/**
* @var boolean
*/
protected $loadFinished;

/**
* modules
*
Expand Down Expand Up @@ -119,9 +124,11 @@ public function loadModule($moduleName)
return $this->loadedModules[$moduleName];
}

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

$this->loadFinished = false;

$result = $this->getEventManager()->trigger(ModuleEvent::EVENT_LOAD_MODULE_RESOLVE, $this, $event, function ($r) {
return (is_object($r));
});
Expand All @@ -138,6 +145,9 @@ public function loadModule($moduleName)

$this->getEventManager()->trigger(ModuleEvent::EVENT_LOAD_MODULE, $this, $event);
$this->loadedModules[$moduleName] = $module;

$this->loadFinished = true;

return $module;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/Zend/ModuleManager/ModuleManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,16 @@ public function testNotFoundModuleThrowsRuntimeException()
$moduleManager = new ModuleManager(array('NotFoundModule'));
$moduleManager->loadModules();
}

public function testCanLoadModuleDuringTheLoadModuleEvent()
{
$configListener = $this->defaultListeners->getConfigListener();
$moduleManager = new ModuleManager(array('LoadOtherModule', 'BarModule'));
$moduleManager->getEventManager()->attachAggregate($this->defaultListeners);
$moduleManager->loadModules();

$config = $configListener->getMergedConfig();
$this->assertTrue(isset($config['loaded']));
$this->assertSame('oh, yeah baby!', $config['loaded']);
}
}
26 changes: 26 additions & 0 deletions tests/Zend/ModuleManager/TestAsset/LoadOtherModule/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ModuleManager
*/

namespace LoadOtherModule;

use Zend\Config\Config;

class Module
{
public function init($moduleManager)
{
$moduleManager->loadModule('BarModule');
}

public function getConfig()
{
return array('loaded' => 'oh, yeah baby!');
}
}

0 comments on commit edb5f72

Please sign in to comment.