summaryrefslogtreecommitdiffstats
path: root/inc/hook.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2019-09-24 15:25:32 +0200
committerSimon Rettberg2019-09-24 15:25:32 +0200
commitd10a3a96e0538b8347472d6c2d350dc2bee86501 (patch)
tree397f62279eaea44be606421396d00ae1bb1b1c0f /inc/hook.inc.php
parent[dnbd3] fix math (diff)
downloadslx-admin-d10a3a96e0538b8347472d6c2d350dc2bee86501.tar.gz
slx-admin-d10a3a96e0538b8347472d6c2d350dc2bee86501.tar.xz
slx-admin-d10a3a96e0538b8347472d6c2d350dc2bee86501.zip
[serversetup-bwlp-ipxe]
Diffstat (limited to 'inc/hook.inc.php')
-rw-r--r--inc/hook.inc.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/inc/hook.inc.php b/inc/hook.inc.php
index bed81aeb..05078f72 100644
--- a/inc/hook.inc.php
+++ b/inc/hook.inc.php
@@ -27,6 +27,26 @@ class Hook
return $retval;
}
+ /**
+ * Load given hook for a specific module only.
+ *
+ * @param string $moduleName Module
+ * @param string $hookName Hook
+ * @param bool $filterBroken return false if the module has missing deps
+ * @return Hook|false hook instance, false on error or if module doesn't have given hook
+ */
+ public static function loadSingle($moduleName, $hookName, $filterBroken = true)
+ {
+ if (Module::get($moduleName) === false) // No such module
+ return false;
+ if ($filterBroken && !Module::isAvailable($moduleName)) // Broken
+ return false;
+ $file = 'modules/' . $moduleName . '/hooks/' . $hookName . '.inc.php';
+ if (!file_exists($file)) // No hook
+ return false;
+ return new Hook($moduleName, $file);
+ }
+
/*
*
*/
@@ -40,4 +60,21 @@ class Hook
$this->file = $hookFile;
}
+ /**
+ * Run the hook's code. The include is expected to return a
+ * value, which will in turn be the return value of this
+ * method.
+ *
+ * @return mixed The return value of the include file, or false on error
+ */
+ public function run()
+ {
+ try {
+ return (include $this->file);
+ } catch (Exception $e) {
+ error_log($e);
+ return false;
+ }
+ }
+
}