summaryrefslogtreecommitdiffstats
path: root/library/Icingadb/Hook/Common/HookUtils.php
diff options
context:
space:
mode:
Diffstat (limited to 'library/Icingadb/Hook/Common/HookUtils.php')
-rw-r--r--library/Icingadb/Hook/Common/HookUtils.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/library/Icingadb/Hook/Common/HookUtils.php b/library/Icingadb/Hook/Common/HookUtils.php
new file mode 100644
index 0000000..8778849
--- /dev/null
+++ b/library/Icingadb/Hook/Common/HookUtils.php
@@ -0,0 +1,39 @@
+<?php
+
+/* Icinga DB Web | (c) 2021 Icinga GmbH | GPLv2 */
+
+namespace Icinga\Module\Icingadb\Hook\Common;
+
+use Icinga\Application\ClassLoader;
+use Icinga\Application\Icinga;
+use Icinga\Application\Modules\Module;
+
+trait HookUtils
+{
+ final public function __construct()
+ {
+ $this->init();
+ }
+
+ /**
+ * Initialize this hook
+ *
+ * Override this in your concrete implementation for any initialization at construction time.
+ */
+ protected function init()
+ {
+ }
+
+ /**
+ * Get the module this hook belongs to
+ *
+ * @return Module
+ */
+ final public function getModule(): Module
+ {
+ $moduleName = ClassLoader::extractModuleName(static::class);
+
+ return Icinga::app()->getModuleManager()
+ ->getModule($moduleName);
+ }
+}