Skip to content

Commit d8b9ade

Browse files
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
1 parent faf9d93 commit d8b9ade

5 files changed

Lines changed: 59 additions & 5 deletions

File tree

modules/core/hooks/hook_sanitycheck.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,22 @@ function core_hook_sanitycheck(&$hookinfo) {
3131
$hookinfo['errors'][] = '[core] You are running PHP version ' . phpversion() . '. SimpleSAMLphp requires version >= 5.1.2, and reccomends version >= 5.2. Please upgrade!';
3232
}
3333

34+
$info = array();
35+
$mihookinfo = array(
36+
'info' => &$info,
37+
);
38+
$availmodules = SimpleSAML_Module::getModules();
39+
SimpleSAML_Module::callHooks('moduleinfo', $mihookinfo);
40+
foreach($info AS $mi => $i) {
41+
if (isset($i['dependencies']) && is_array($i['dependencies'])) {
42+
foreach ($i['dependencies'] AS $dep) {
43+
// $hookinfo['info'][] = '[core] Module ' . $mi . ' requires ' . $dep;
44+
if (!in_array($dep, $availmodules)) {
45+
$hookinfo['errors'][] = '[core] Module dependency not met: ' . $mi . ' requires ' . $dep;
46+
}
47+
}
48+
}
49+
}
50+
3451
}
3552
?>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* This hook lets the module describe itself.
4+
*
5+
* @param array &$moduleinfo The links on the frontpage, split into sections.
6+
*/
7+
function modinfo_hook_moduleinfo(&$moduleinfo) {
8+
assert('is_array($moduleinfo)');
9+
assert('array_key_exists("info", $moduleinfo)');
10+
11+
12+
$moduleinfo['info']['modinfo'] = array(
13+
'name' => array('en' => 'Module information'),
14+
'description' => array('en' => 'This module lists all available modules, and tells whether they are enabled or not.'),
15+
16+
'dependencies' => array('core'),
17+
'uses' => array('sanitycheck'),
18+
);
19+
20+
}
21+
?>

modules/modinfo/www/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
foreach($modules as $m) {
99
$modinfo[$m] = array(
1010
'enabled' => SimpleSAML_Module::isModuleEnabled($m),
11-
);
11+
);
1212
}
1313

1414
$config = SimpleSAML_Configuration::getInstance();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* This hook lets the module describe itself.
4+
*
5+
* @param array &$moduleinfo The links on the frontpage, split into sections.
6+
*/
7+
function sanitycheck_hook_moduleinfo(&$moduleinfo) {
8+
assert('is_array($moduleinfo)');
9+
assert('array_key_exists("info", $moduleinfo)');
10+
11+
$moduleinfo['info']['sanitycheck'] = array(
12+
'name' => array('en' => 'Sanity check'),
13+
'description' => array('en' => 'This module adds functionality for other modules to provide santity checks.'),
14+
15+
'dependencies' => array('core'),
16+
'uses' => array('cron'),
17+
);
18+
19+
}
20+
?>

modules/sanitycheck/hooks/hook_sanitycheck.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ function sanitycheck_hook_sanitycheck(&$hookinfo) {
99
assert('array_key_exists("errors", $hookinfo)');
1010
assert('array_key_exists("info", $hookinfo)');
1111

12-
13-
1412
$hookinfo['info'][] = '[sanitycheck] At least the sanity check it self is working :)';
15-
16-
1713

1814
}
1915
?>

0 commit comments

Comments
 (0)