ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
SimpleSAML\Module Class Reference
+ Collaboration diagram for SimpleSAML\Module:

Static Public Member Functions

static autoloadPSR0 ($className)
 Autoload function for SimpleSAMLphp modules following PSR-0. More...
 
static autoloadPSR4 ($className)
 Autoload function for SimpleSAMLphp modules following PSR-4. More...
 
static getModuleDir ($module)
 Retrieve the base directory for a module. More...
 
static isModuleEnabled ($module)
 Determine whether a module is enabled. More...
 
static getModules ()
 Get available modules. More...
 
static resolveClass ($id, $type, $subclass=null)
 Resolve module class. More...
 
static getModuleURL ($resource, array $parameters=array())
 Get absolute URL to a specified module resource. More...
 
static getModuleHooks ($module)
 Get the available hooks for a given module. More...
 
static callHooks ($hook, &$data=null)
 Call a hook in all enabled modules. More...
 

Static Public Attributes

static $modules = array()
 
static $module_info = array()
 

Static Private Member Functions

static isModuleEnabledWithConf ($module, $mod_config)
 

Detailed Description

Definition at line 12 of file Module.php.

Member Function Documentation

◆ autoloadPSR0()

static SimpleSAML\Module::autoloadPSR0 (   $className)
static

Autoload function for SimpleSAMLphp modules following PSR-0.

Parameters
string$classNameName of the class.
Deprecated:
This method will be removed in SSP 2.0.

TODO: this autoloader should be removed once everything has been migrated to namespaces.

Definition at line 39 of file Module.php.

40 {
41 $modulePrefixLength = strlen('sspmod_');
42 $classPrefix = substr($className, 0, $modulePrefixLength);
43 if ($classPrefix !== 'sspmod_') {
44 return;
45 }
46
47 $modNameEnd = strpos($className, '_', $modulePrefixLength);
48 $module = substr($className, $modulePrefixLength, $modNameEnd - $modulePrefixLength);
49 $path = explode('_', substr($className, $modNameEnd + 1));
50
51 if (!self::isModuleEnabled($module)) {
52 return;
53 }
54
55 $file = self::getModuleDir($module).'/lib/'.join('/', $path).'.php';
56 if (!file_exists($file)) {
57 return;
58 }
59 require_once($file);
60
61 if (!class_exists($className, false) && !interface_exists($className, false)) {
62 // the file exists, but the class is not defined. Is it using namespaces?
63 $nspath = join('\\', $path);
64 if (class_exists('SimpleSAML\Module\\'.$module.'\\'.$nspath) ||
65 interface_exists('SimpleSAML\Module\\'.$module.'\\'.$nspath)
66 ) {
67 // the class has been migrated, create an alias and warn about it
69 "The class or interface '$className' is now using namespaces, please use 'SimpleSAML\\Module\\".
70 $module."\\".$nspath."' instead."
71 );
72 class_alias("SimpleSAML\\Module\\$module\\$nspath", $className);
73 }
74 }
75 }
static warning($string)
Definition: Logger.php:179
static getModuleDir($module)
Retrieve the base directory for a module.
Definition: Module.php:122
if($modEnd===false) $module
Definition: module.php:59
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file

References $file, $module, $path, and SimpleSAML\Logger\warning().

+ Here is the call graph for this function:

◆ autoloadPSR4()

static SimpleSAML\Module::autoloadPSR4 (   $className)
static

Autoload function for SimpleSAMLphp modules following PSR-4.

Parameters
string$classNameName of the class.

Definition at line 83 of file Module.php.

84 {
85 $elements = explode('\\', $className);
86 if ($elements[0] === '') { // class name starting with /, ignore
87 array_shift($elements);
88 }
89 if (count($elements) < 4) {
90 return; // it can't be a module
91 }
92 if (array_shift($elements) !== 'SimpleSAML') {
93 return; // the first element is not "SimpleSAML"
94 }
95 if (array_shift($elements) !== 'Module') {
96 return; // the second element is not "module"
97 }
98
99 // this is a SimpleSAMLphp module following PSR-4
100 $module = array_shift($elements);
101 if (!self::isModuleEnabled($module)) {
102 return; // module not enabled, avoid giving out any information at all
103 }
104
105 $file = self::getModuleDir($module).'/lib/'.implode('/', $elements).'.php';
106
107 if (file_exists($file)) {
108 require_once($file);
109 }
110 }

References $file, and $module.

◆ callHooks()

static SimpleSAML\Module::callHooks (   $hook,
$data = null 
)
static

Call a hook in all enabled modules.

This function iterates over all enabled modules and calls a hook in each module.

Parameters
string$hookThe name of the hook.
mixed&$dataThe data which should be passed to each hook. Will be passed as a reference.
Exceptions

SimpleSAML_Error_Exception If an invalid hook is found in a module.

Definition at line 364 of file Module.php.

365 {
366 assert('is_string($hook)');
367
369 $config = \SimpleSAML_Configuration::getOptionalConfig()->getArray('module.enable', array());
370 sort($modules);
371 foreach ($modules as $module) {
372 if (!self::isModuleEnabledWithConf($module, $config)) {
373 continue;
374 }
375
376 if (!isset(self::$module_info[$module]['hooks'])) {
377 self::$module_info[$module]['hooks'] = self::getModuleHooks($module);
378 }
379
380 if (!isset(self::$module_info[$module]['hooks'][$hook])) {
381 continue;
382 }
383
384 require_once(self::$module_info[$module]['hooks'][$hook]['file']);
385
386 if (!is_callable(self::$module_info[$module]['hooks'][$hook]['func'])) {
387 throw new \SimpleSAML_Error_Exception('Invalid hook \''.$hook.'\' for module \''.$module.'\'.');
388 }
389
390 $fn = self::$module_info[$module]['hooks'][$hook]['func'];
391 $fn($data);
392 }
393 }
static getModuleHooks($module)
Get the available hooks for a given module.
Definition: Module.php:325
static getModules()
Get available modules.
Definition: Module.php:204
static $modules
Definition: Module.php:20
static getOptionalConfig($filename='config.php', $configSet='simplesaml')
Load a configuration file from a configuration set.

Referenced by core_hook_sanitycheck(), sspmod_portal_Portal\getLoginInfo(), portal_hook_htmlinject(), SimpleSAML\Module\cron\Cron\runTag(), sanitycheck_hook_cron(), and SimpleSAML_exception_handler().

+ Here is the caller graph for this function:

◆ getModuleDir()

static SimpleSAML\Module::getModuleDir (   $module)
static

Retrieve the base directory for a module.

The returned path name will be an absolute path.

Parameters
string$moduleName of the module
Returns
string The base directory of a module.

Definition at line 122 of file Module.php.

123 {
124 $baseDir = dirname(dirname(dirname(__FILE__))).'/modules';
126
127 return $moduleDir;
128 }
if( $url===false) if(!SimpleSAML\Module::isModuleEnabled($module)) if(strpos( $url, '\\') !==false) elseif(strpos($url, './') !==false) $moduleDir
Definition: module.php:79

References $baseDir, $module, and $moduleDir.

Referenced by SimpleSAML_XHTML_Template\findThemeTemplateDirs(), SimpleSAML\Locale\Translate\getDictionary(), and sspmod_core_Auth_Process_AttributeMap\loadMapFile().

+ Here is the caller graph for this function:

◆ getModuleHooks()

static SimpleSAML\Module::getModuleHooks (   $module)
static

Get the available hooks for a given module.

Parameters
string$moduleThe module where we should look for hooks.
Returns
array An array with the hooks available for this module. Each element is an array with two keys: 'file' points to the file that contains the hook, and 'func' contains the name of the function implementing that hook. When there are no hooks defined, an empty array is returned.

Definition at line 325 of file Module.php.

326 {
327 if (isset(self::$modules[$module]['hooks'])) {
328 return self::$modules[$module]['hooks'];
329 }
330
331 $hook_dir = self::getModuleDir($module).'/hooks';
332 if (!is_dir($hook_dir)) {
333 return array();
334 }
335
336 $hooks = array();
337 $files = scandir($hook_dir);
338 foreach ($files as $file) {
339 if ($file[0] === '.') {
340 continue;
341 }
342
343 if (!preg_match('/hook_(\w+)\.php/', $file, $matches)) {
344 continue;
345 }
346 $hook_name = $matches[1];
347 $hook_func = $module.'_hook_'.$hook_name;
348 $hooks[$hook_name] = array('file' => $hook_dir.'/'.$file, 'func' => $hook_func);
349 }
350 return $hooks;
351 }
$files
Definition: add-vimline.php:18

◆ getModules()

static SimpleSAML\Module::getModules ( )
static

Get available modules.

Returns
array One string for each module.
Exceptions

Exception If we cannot open the module's directory.

Definition at line 204 of file Module.php.

205 {
206 if (!empty(self::$modules)) {
207 return self::$modules;
208 }
209
211
212 $dh = scandir($path);
213 if ($dh === false) {
214 throw new \Exception('Unable to open module directory "'.$path.'".');
215 }
216
217 foreach ($dh as $f) {
218 if ($f[0] === '.') {
219 continue;
220 }
221
222 if (!is_dir($path.'/'.$f)) {
223 continue;
224 }
225
226 self::$modules[] = $f;
227 }
228
229 return self::$modules;
230 }

References $path.

Referenced by core_hook_sanitycheck().

+ Here is the caller graph for this function:

◆ getModuleURL()

static SimpleSAML\Module::getModuleURL (   $resource,
array  $parameters = array() 
)
static

Get absolute URL to a specified module resource.

This function creates an absolute URL to a resource stored under ".../modules/<module>/www/".

Parameters
string$resourceResource path, on the form "<module name>/<resource>"
array$parametersExtra parameters which should be added to the URL. Optional.
Returns
string The absolute URL to the given resource.

Definition at line 303 of file Module.php.

304 {
305 assert('is_string($resource)');
306 assert('$resource[0] !== "/"');
307
308 $url = Utils\HTTP::getBaseURL().'module.php/'.$resource;
309 if (!empty($parameters)) {
310 $url = Utils\HTTP::addURLParameters($url, $parameters);
311 }
312 return $url;
313 }
static getBaseURL()
Retrieve the base URL of the SimpleSAMLphp installation.
Definition: HTTP.php:598
$url

Referenced by sspmod_saml_Auth_Source_SP\__construct(), sspmod_saml_Auth_Source_SP\askForIdPChange(), sspmod_authfacebook_Auth_Source_Facebook\authenticate(), sspmod_authtwitter_Auth_Source_Twitter\authenticate(), sspmod_authYubiKey_Auth_Source_YubiKey\authenticate(), sspmod_cas_Auth_Source_CAS\authenticate(), sspmod_core_Auth_UserPassBase\authenticate(), sspmod_core_Auth_UserPassOrgBase\authenticate(), sspmod_exampleauth_Auth_Source_External\authenticate(), sspmod_multiauth_Auth_Source_MultiAuth\authenticate(), SimpleSAML_Utilities\createHttpPostRedirectLink(), sspmod_cas_Auth_Source_CAS\finalStep(), SimpleSAML\Utils\Auth\getAdminLoginURL(), getBaseURL(), SimpleSAML\Auth\Simple\getLoginURL(), SimpleSAML\Auth\Simple\getLogoutURL(), sspmod_adfs_IdP_ADFS\getLogoutURL(), sspmod_saml_IdP_SAML2\getLogoutURL(), sspmod_saml_Auth_Source_SP\getMetadataURL(), SimpleSAML\Utils\HTTP\getSecurePOSTRedirectURL(), SimpleSAML_IdP\handleLogoutRequest(), sspmod_consent_Logout\postLogout(), sspmod_authX509_Auth_Process_ExpiryWarning\process(), sspmod_cdc_Auth_Process_CDC\process(), sspmod_consent_Auth_Process_Consent\process(), sspmod_core_Auth_Process_WarnShortSSOInterval\process(), sspmod_exampleauth_Auth_Process_RedirectTest\process(), sspmod_expirycheck_Auth_Process_ExpiryDate\process(), sspmod_preprodwarning_Auth_Process_Warning\process(), sspmod_saml_Auth_Source_SP\startDisco(), SimpleSAML\IdP\IFrameLogoutHandler\startLogout(), sspmod_saml_Auth_Source_SP\startSSO1(), sspmod_authorize_Auth_Process_Authorize\unauthorized(), and sspmod_saml_Auth_Process_ExpectedAuthnContextClassRef\unauthorized().

+ Here is the caller graph for this function:

◆ isModuleEnabled()

static SimpleSAML\Module::isModuleEnabled (   $module)
static

Determine whether a module is enabled.

Will return false if the given module doesn't exist.

Parameters
string$moduleName of the module
Returns
bool True if the given module is enabled, false otherwise.
Exceptions

Exception If module.enable is set and is not boolean.

Definition at line 142 of file Module.php.

143 {
145 return self::isModuleEnabledWithConf($module, $config->getArray('module.enable', array()));
146 }
static isModuleEnabledWithConf($module, $mod_config)
Definition: Module.php:149

References $config, $module, and SimpleSAML_Configuration\getOptionalConfig().

+ Here is the call graph for this function:

◆ isModuleEnabledWithConf()

static SimpleSAML\Module::isModuleEnabledWithConf (   $module,
  $mod_config 
)
staticprivate

Definition at line 149 of file Module.php.

150 {
151 if (isset(self::$module_info[$module]['enabled'])) {
152 return self::$module_info[$module]['enabled'];
153 }
154
155 if (!empty(self::$modules) && !in_array($module, self::$modules, true)) {
156 return false;
157 }
158
160
161 if (!is_dir($moduleDir)) {
162 self::$module_info[$module]['enabled'] = false;
163 return false;
164 }
165
166 if (isset($mod_config[$module])) {
167 if (is_bool($mod_config[$module])) {
168 self::$module_info[$module]['enabled'] = $mod_config[$module];
169 return $mod_config[$module];
170 }
171
172 throw new \Exception("Invalid module.enable value for the '$module' module.");
173 }
174
175 if (assert_options(ASSERT_ACTIVE) &&
176 !file_exists($moduleDir.'/default-enable') &&
177 !file_exists($moduleDir.'/default-disable')
178 ) {
179 \SimpleSAML\Logger::error("Missing default-enable or default-disable file for the module $module");
180 }
181
182 if (file_exists($moduleDir.'/enable')) {
183 self::$module_info[$module]['enabled'] = true;
184 return true;
185 }
186
187 if (!file_exists($moduleDir.'/disable') && file_exists($moduleDir.'/default-enable')) {
188 self::$module_info[$module]['enabled'] = true;
189 return true;
190 }
191
192 self::$module_info[$module]['enabled'] = false;
193 return false;
194 }
static error($string)
Definition: Logger.php:168

References $module, $moduleDir, and SimpleSAML\Logger\error().

+ Here is the call graph for this function:

◆ resolveClass()

static SimpleSAML\Module::resolveClass (   $id,
  $type,
  $subclass = null 
)
static

Resolve module class.

This function takes a string on the form "<module>:<class>" and converts it to a class name. It can also check that the given class is a subclass of a specific class. The resolved classname will be "sspmod_<module>_<$type>_<class>.

It is also possible to specify a full classname instead of <module>:<class>.

An exception will be thrown if the class can't be resolved.

Parameters
string$idThe string we should resolve.
string$typeThe type of the class.
string | null$subclassThe class should be a subclass of this class. Optional.
Returns
string The classname.
Exceptions

Exception If the class cannot be resolved.

Definition at line 252 of file Module.php.

253 {
254 assert('is_string($id)');
255 assert('is_string($type)');
256 assert('is_string($subclass) || is_null($subclass)');
257
258 $tmp = explode(':', $id, 2);
259 if (count($tmp) === 1) { // no module involved
260 $className = $tmp[0];
261 if (!class_exists($className)) {
262 throw new \Exception("Could not resolve '$id': no class named '$className'.");
263 }
264 } else { // should be a module
265 // make sure empty types are handled correctly
266 $type = (empty($type)) ? '_' : '_'.$type.'_';
267
268 // check for the old-style class names
269 $className = 'sspmod_'.$tmp[0].$type.$tmp[1];
270
271 if (!class_exists($className)) {
272 // check for the new-style class names, using namespaces
273 $type = str_replace('_', '\\', $type);
274 $newClassName = 'SimpleSAML\Module\\'.$tmp[0].$type.$tmp[1];
275
276 if (!class_exists($newClassName)) {
277 throw new \Exception("Could not resolve '$id': no class named '$className' or '$newClassName'.");
278 }
279 $className = $newClassName;
280 }
281 }
282
283 if ($subclass !== null && !is_subclass_of($className, $subclass)) {
284 throw new \Exception(
285 'Could not resolve \''.$id.'\': The class \''.$className.'\' isn\'t a subclass of \''.$subclass.'\'.'
286 );
287 }
288
289 return $className;
290 }
PHPExcel root directory.
Definition: PHPExcel.php:30
if(!array_key_exists('StateId', $_REQUEST)) $id
$type

References $id, and $type.

Referenced by SimpleSAML_Stats\createOutput(), sspmod_statistics_StatDataset\getDelimiterPresentation(), sspmod_statistics_Ruleset\getRule(), SimpleSAML_Metadata_MetaDataStorageSource\getSource(), SimpleSAML_Auth_Source\parseAuthSource(), SimpleSAML_Auth_ProcessingChain\parseFilter(), and sspmod_consent_Store\parseStoreConfig().

+ Here is the caller graph for this function:

Field Documentation

◆ $module_info

SimpleSAML\Module::$module_info = array()
static

Definition at line 27 of file Module.php.

◆ $modules

SimpleSAML\Module::$modules = array()
static

Definition at line 20 of file Module.php.


The documentation for this class was generated from the following file: