From d8b9ade1594f39cab029dd0aa8298522da8abe7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no> Date: Fri, 14 Nov 2008 21:55:18 +0000 Subject: [PATCH] Add a new hook to let a module add information about it self, also add a sanitycheck to resolve missing module dependencies git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@999 44740490-163a-0410-bde0-09ae8108e29a --- modules/core/hooks/hook_sanitycheck.php | 17 +++++++++++++++ modules/modinfo/hooks/hook_moduleinfo.php | 21 +++++++++++++++++++ modules/modinfo/www/index.php | 2 +- modules/sanitycheck/hooks/hook_moduleinfo.php | 20 ++++++++++++++++++ .../sanitycheck/hooks/hook_sanitycheck.php | 4 ---- 5 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 modules/modinfo/hooks/hook_moduleinfo.php create mode 100644 modules/sanitycheck/hooks/hook_moduleinfo.php diff --git a/modules/core/hooks/hook_sanitycheck.php b/modules/core/hooks/hook_sanitycheck.php index c2e8e6fb7..905580156 100644 --- a/modules/core/hooks/hook_sanitycheck.php +++ b/modules/core/hooks/hook_sanitycheck.php @@ -31,5 +31,22 @@ function core_hook_sanitycheck(&$hookinfo) { $hookinfo['errors'][] = '[core] You are running PHP version ' . phpversion() . '. SimpleSAMLphp requires version >= 5.1.2, and reccomends version >= 5.2. Please upgrade!'; } + $info = array(); + $mihookinfo = array( + 'info' => &$info, + ); + $availmodules = SimpleSAML_Module::getModules(); + SimpleSAML_Module::callHooks('moduleinfo', $mihookinfo); + foreach($info AS $mi => $i) { + if (isset($i['dependencies']) && is_array($i['dependencies'])) { + foreach ($i['dependencies'] AS $dep) { + // $hookinfo['info'][] = '[core] Module ' . $mi . ' requires ' . $dep; + if (!in_array($dep, $availmodules)) { + $hookinfo['errors'][] = '[core] Module dependency not met: ' . $mi . ' requires ' . $dep; + } + } + } + } + } ?> \ No newline at end of file diff --git a/modules/modinfo/hooks/hook_moduleinfo.php b/modules/modinfo/hooks/hook_moduleinfo.php new file mode 100644 index 000000000..3518f7012 --- /dev/null +++ b/modules/modinfo/hooks/hook_moduleinfo.php @@ -0,0 +1,21 @@ +<?php +/** + * This hook lets the module describe itself. + * + * @param array &$moduleinfo The links on the frontpage, split into sections. + */ +function modinfo_hook_moduleinfo(&$moduleinfo) { + assert('is_array($moduleinfo)'); + assert('array_key_exists("info", $moduleinfo)'); + + + $moduleinfo['info']['modinfo'] = array( + 'name' => array('en' => 'Module information'), + 'description' => array('en' => 'This module lists all available modules, and tells whether they are enabled or not.'), + + 'dependencies' => array('core'), + 'uses' => array('sanitycheck'), + ); + +} +?> \ No newline at end of file diff --git a/modules/modinfo/www/index.php b/modules/modinfo/www/index.php index 1de275fd7..74897f025 100644 --- a/modules/modinfo/www/index.php +++ b/modules/modinfo/www/index.php @@ -8,7 +8,7 @@ $modinfo = array(); foreach($modules as $m) { $modinfo[$m] = array( 'enabled' => SimpleSAML_Module::isModuleEnabled($m), - ); + ); } $config = SimpleSAML_Configuration::getInstance(); diff --git a/modules/sanitycheck/hooks/hook_moduleinfo.php b/modules/sanitycheck/hooks/hook_moduleinfo.php new file mode 100644 index 000000000..ff9642df5 --- /dev/null +++ b/modules/sanitycheck/hooks/hook_moduleinfo.php @@ -0,0 +1,20 @@ +<?php +/** + * This hook lets the module describe itself. + * + * @param array &$moduleinfo The links on the frontpage, split into sections. + */ +function sanitycheck_hook_moduleinfo(&$moduleinfo) { + assert('is_array($moduleinfo)'); + assert('array_key_exists("info", $moduleinfo)'); + + $moduleinfo['info']['sanitycheck'] = array( + 'name' => array('en' => 'Sanity check'), + 'description' => array('en' => 'This module adds functionality for other modules to provide santity checks.'), + + 'dependencies' => array('core'), + 'uses' => array('cron'), + ); + +} +?> \ No newline at end of file diff --git a/modules/sanitycheck/hooks/hook_sanitycheck.php b/modules/sanitycheck/hooks/hook_sanitycheck.php index d551692a8..045b7f4f4 100644 --- a/modules/sanitycheck/hooks/hook_sanitycheck.php +++ b/modules/sanitycheck/hooks/hook_sanitycheck.php @@ -9,11 +9,7 @@ function sanitycheck_hook_sanitycheck(&$hookinfo) { assert('array_key_exists("errors", $hookinfo)'); assert('array_key_exists("info", $hookinfo)'); - - $hookinfo['info'][] = '[sanitycheck] At least the sanity check it self is working :)'; - - } ?> \ No newline at end of file -- GitLab