summaryrefslogtreecommitdiffstats
path: root/inc/hook.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/hook.inc.php')
-rw-r--r--inc/hook.inc.php19
1 files changed, 11 insertions, 8 deletions
diff --git a/inc/hook.inc.php b/inc/hook.inc.php
index 05078f72..f7ca617d 100644
--- a/inc/hook.inc.php
+++ b/inc/hook.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Generic helper for getting and executing hooks.
*/
@@ -11,11 +13,12 @@ class Hook
* Internally, this scans for "modules/<*>/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
+ * @return Hook[] list of modules with requested hooks
*/
- public static function load($hookName, $filterBroken = true)
+ public static function load(string $hookName, bool $filterBroken = true): array
{
$retval = array();
foreach (glob('modules/*/hooks/' . $hookName . '.inc.php', GLOB_NOSORT) as $file) {
@@ -33,17 +36,17 @@ class Hook
* @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
+ * @return ?Hook hook instance, false on error or if module doesn't have given hook
*/
- public static function loadSingle($moduleName, $hookName, $filterBroken = true)
+ public static function loadSingle(string $moduleName, string $hookName, bool $filterBroken = true): ?Hook
{
if (Module::get($moduleName) === false) // No such module
- return false;
+ return null;
if ($filterBroken && !Module::isAvailable($moduleName)) // Broken
- return false;
+ return null;
$file = 'modules/' . $moduleName . '/hooks/' . $hookName . '.inc.php';
if (!file_exists($file)) // No hook
- return false;
+ return null;
return new Hook($moduleName, $file);
}
@@ -72,7 +75,7 @@ class Hook
try {
return (include $this->file);
} catch (Exception $e) {
- error_log($e);
+ error_log($e->getMessage());
return false;
}
}