From 4caf8a3b5d987ab262f49929701d22a60e4ea4a2 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Wed, 20 Aug 2008 09:11:30 +0000
Subject: [PATCH] Add module hook interface.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@822 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Module.php | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/lib/SimpleSAML/Module.php b/lib/SimpleSAML/Module.php
index 18a332b51..9d0f1fdcb 100644
--- a/lib/SimpleSAML/Module.php
+++ b/lib/SimpleSAML/Module.php
@@ -146,6 +146,37 @@ class SimpleSAML_Module {
 		return SimpleSAML_Utilities::selfURLhost() . '/' . $config->getBaseURL() . 'module.php/' . $resource;
 	}
 
+
+	/**
+	 * Call a hook in all enabled modules.
+	 *
+	 * This function iterates over all enabled modules and calls a hook in each module.
+	 *
+	 * @param string $hook  The name of the hook.
+	 * @param mixed &$data  The data which should be passed to each hook. Will be passed as a reference.
+	 */
+	public static function callHooks($hook, &$data = NULL) {
+		assert('is_string($hook)');
+
+		foreach (self::getModules() as $module) {
+			if (!self::isModuleEnabled($module)) {
+				continue;
+			}
+
+			$hookfile = self::getModuleDir($module) . '/hooks/hook_' . $hook . '.php';
+			if (!file_exists($hookfile)) {
+				continue;
+			}
+
+			require_once($hookfile);
+
+			$hookfunc = $module . '_hook_' . $hook;
+			assert('is_callable($hookfunc)');
+
+			$hookfunc($data);
+		}
+	}
+
 }
 
 ?>
\ No newline at end of file
-- 
GitLab