From 444fdadf13c0bded00b6eb82a7f10cbbdf4942af Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 24 Jul 2015 14:23:48 +0200 Subject: [PATCH] Allow to get unloaded modules via Manager::getModule() refs #9644 --- .../Icinga/Application/Modules/Manager.php | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/library/Icinga/Application/Modules/Manager.php b/library/Icinga/Application/Modules/Manager.php index 9de86db18..8a3970841 100644 --- a/library/Icinga/Application/Modules/Manager.php +++ b/library/Icinga/Application/Modules/Manager.php @@ -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 - * @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)) { - throw new ProgrammingError( - 'Cannot access module %s as it hasn\'t been loaded', - $name - ); + if ($this->hasLoaded($name)) { + return $this->loadedModules[$name]; + } elseif (! (bool) $assertLoaded) { + 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 + ); } /**