Allow to get unloaded modules via Manager::getModule()

refs #9644
This commit is contained in:
Eric Lippmann 2015-07-24 14:23:48 +02:00
parent ec1ddd82b3
commit 444fdadf13

View File

@ -408,22 +408,25 @@ class Manager
} }
/** /**
* Return the module instance of the given module when it is loaded * Get a module
* *
* @param string $name The module name to return * @param string $name Name of the module
* @param bool $assertLoaded Whether or not to throw an exception if the module hasn't been loaded
* *
* @return Module * @return Module
* @throws ProgrammingError When the module hasn't been loaded * @throws ProgrammingError If the module hasn't been loaded
*/ */
public function getModule($name) public function getModule($name, $assertLoaded = true)
{ {
if (!$this->hasLoaded($name)) { if ($this->hasLoaded($name)) {
throw new ProgrammingError( return $this->loadedModules[$name];
'Cannot access module %s as it hasn\'t been loaded', } elseif (! (bool) $assertLoaded) {
$name return new Module($this->app, $name, $this->getModuleDir($name));
);
} }
return $this->loadedModules[$name]; throw new ProgrammingError(
'Can\'t access module %s because it hasn\'t been loaded',
$name
);
} }
/** /**