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,23 +408,26 @@ 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)) {
return $this->loadedModules[$name];
} elseif (! (bool) $assertLoaded) {
return new Module($this->app, $name, $this->getModuleDir($name));
}
throw new ProgrammingError( throw new ProgrammingError(
'Cannot access module %s as it hasn\'t been loaded', 'Can\'t access module %s because it hasn\'t been loaded',
$name $name
); );
} }
return $this->loadedModules[$name];
}
/** /**
* Return an array containing information objects for each available module * Return an array containing information objects for each available module