From 627d18ede199339ad3a5bc8b85c0cc71616a6868 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 2 Mar 2017 16:00:32 +0100 Subject: [inc/Hook] New helper for loading hooks --- inc/hook.inc.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 inc/hook.inc.php (limited to 'inc/hook.inc.php') diff --git a/inc/hook.inc.php b/inc/hook.inc.php new file mode 100644 index 00000000..bed81aeb --- /dev/null +++ b/inc/hook.inc.php @@ -0,0 +1,43 @@ +/hooks/$hookName.inc.php" + * and optionally checks if the module's dependencies are fulfilled, + * then returns a list of all matching modules. + * @param string $hookName Name of hook to search for. + * @param bool $filterBroken if true, modules that have a hook but have missing deps will not be returned + * @return \Hook[] list of modules with requested hooks + */ + public static function load($hookName, $filterBroken = true) + { + $retval = array(); + foreach (glob('modules/*/hooks/' . $hookName . '.inc.php', GLOB_NOSORT) as $file) { + preg_match('#^modules/([^/]+)/#', $file, $out); + if ($filterBroken && !Module::isAvailable($out[1])) + continue; + $retval[] = new Hook($out[1], $file); + } + return $retval; + } + + /* + * + */ + + public $moduleId; + public $file; + + private function __construct($module, $hookFile) + { + $this->moduleId = $module; + $this->file = $hookFile; + } + +} -- cgit v1.2.3-55-g7522