From 771bc1054daa33d8bf46c8f7a23bffb26e24daf4 Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Mon, 7 Nov 2022 14:50:28 -0500 Subject: [PATCH] [LorisInstance] add getModule function LorisInstance already has functions to check if a module exists, get the module directories, etc. This adds a getModule to replace \Module::factory() so that the code dealing with modules can be centralized in one place. --- src/LorisInstance.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/LorisInstance.php b/src/LorisInstance.php index 56a4d8a0cc2..d84e194378b 100644 --- a/src/LorisInstance.php +++ b/src/LorisInstance.php @@ -76,7 +76,8 @@ public function getActiveModules(): array $modules = []; foreach ($mnames as $name) { try { - $modules[] = \Module::factory($this, $name); + $mod = \Module::factory($this, $name); + $modules[] = $mod; } catch (\LorisModuleMissingException $e) { error_log($e->getMessage() . " " . $e->getTraceAsString()); } @@ -116,6 +117,18 @@ public function hasModule(string $name) : bool return false; } + /** + * Get the \Module class for the module named $name, + * if enabled on this LORIS instance or throw an exception + * if it doesn't exist. + * + * @return \Module + */ + public function getModule(string $name) : \Module + { + return \Module::factory($this, $name); + } + /** * Returns an NDB_Config object used for interacting with configuration * settings for this instance.