20 public static $modules = array();
27 public static $module_info = array();
41 $baseDir = dirname(dirname(dirname(__FILE__))).
'/modules';
62 return self::isModuleEnabledWithConf(
$module,
$config->getArray(
'module.enable', array()));
68 if (isset(self::$module_info[
$module][
'enabled'])) {
69 return self::$module_info[
$module][
'enabled'];
72 if (!empty(self::$modules) && !in_array(
$module, self::$modules,
true)) {
79 self::$module_info[
$module][
'enabled'] =
false;
83 if (isset($mod_config[
$module])) {
84 if (is_bool($mod_config[
$module])) {
89 throw new \Exception(
"Invalid module.enable value for the '$module' module.");
92 if (assert_options(ASSERT_ACTIVE) &&
100 self::$module_info[
$module][
'enabled'] =
true;
105 self::$module_info[
$module][
'enabled'] =
true;
109 self::$module_info[
$module][
'enabled'] =
false;
123 if (!empty(self::$modules)) {
124 return self::$modules;
127 $path = self::getModuleDir(
'.');
129 $dh = scandir(
$path);
131 throw new \Exception(
'Unable to open module directory "'.
$path.
'".');
134 foreach ($dh as
$f) {
143 self::$modules[] =
$f;
146 return self::$modules;
171 assert(is_string(
$id));
172 assert(is_string(
$type));
173 assert(is_string($subclass) || $subclass ===
null);
175 $tmp = explode(
':',
$id, 2);
176 if (count($tmp) === 1) {
177 $className = $tmp[0];
178 if (!class_exists($className)) {
179 throw new \Exception(
"Could not resolve '$id': no class named '$className'.");
186 $className =
'sspmod_'.$tmp[0].$type.$tmp[1];
188 if (!class_exists($className)) {
191 $newClassName =
'SimpleSAML\Module\\'.$tmp[0].$type.$tmp[1];
193 if (!class_exists($newClassName)) {
194 throw new \Exception(
"Could not resolve '$id': no class named '$className' or '$newClassName'.");
196 $className = $newClassName;
200 if ($subclass !==
null && !is_subclass_of($className, $subclass)) {
201 throw new \Exception(
202 'Could not resolve \''.
$id.
'\': The
class \
''.$className.
'\' isn\
't a subclass of \''.$subclass.
'\'.
'
220 public static function getModuleURL($resource, array $parameters = array())
222 assert(is_string($resource));
223 assert($resource[0] !== '/
');
225 $url = Utils\HTTP::getBaseURL().'module.php/
'.$resource;
226 if (!empty($parameters)) {
227 $url = Utils\HTTP::addURLParameters($url, $parameters);
242 public static function getModuleHooks($module)
244 if (isset(self::$modules[$module]['hooks
'])) {
245 return self::$modules[$module]['hooks
'];
248 $hook_dir = self::getModuleDir($module).'/hooks
';
249 if (!is_dir($hook_dir)) {
254 $files = scandir($hook_dir);
255 foreach ($files as $file) {
256 if ($file[0] === '.
') {
260 if (!preg_match('/hook_(\w+)\.
php/
', $file, $matches)) {
263 $hook_name = $matches[1];
264 $hook_func = $module.'_hook_
'.$hook_name;
265 $hooks[$hook_name] = array('file
' => $hook_dir.'/
'.$file, 'func
' => $hook_func);
281 public static function callHooks($hook, &$data = null)
283 assert(is_string($hook));
285 $modules = self::getModules();
286 $config = \SimpleSAML_Configuration::getOptionalConfig()->getArray('module.enable
', array());
288 foreach ($modules as $module) {
289 if (!self::isModuleEnabledWithConf($module, $config)) {
293 if (!isset(self::$module_info[$module]['hooks
'])) {
294 self::$module_info[$module]['hooks
'] = self::getModuleHooks($module);
297 if (!isset(self::$module_info[$module]['hooks
'][$hook])) {
301 require_once(self::$module_info[$module]['hooks
'][$hook]['file
']);
303 if (!is_callable(self::$module_info[$module]['hooks
'][$hook]['func
'])) {
304 throw new \SimpleSAML_Error_Exception('Invalid hook \
''.$hook.
'\' for module \
''.$module.
'\'.
');
307 $fn = self::$module_info[$module]['hooks
'][$hook]['func
'];
An exception for terminatinating execution or to throw for unit testing.
static getModuleDir($module)
Retrieve the base directory for a module.
static getModules()
Get available modules.
static resolveClass($id, $type, $subclass=null)
Resolve module class.
static isModuleEnabled($module)
Determine whether a module is enabled.
static isModuleEnabledWithConf($module, $mod_config)
static getOptionalConfig($filename='config.php', $configSet='simplesaml')
Load a configuration file from a configuration set.
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
if(!array_key_exists('StateId', $_REQUEST)) $id
if($modEnd===false) $module
if( $url===false) if(!SimpleSAML\Module::isModuleEnabled($module)) if(strpos( $url, '\\') !==false) elseif(strpos($url, './') !==false) $moduleDir
Attribute-related utility methods.