ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SimpleSAML\Module Class Reference
+ Collaboration diagram for SimpleSAML\Module:

Static Public Member Functions

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

◆ 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 281 of file Module.php.

282 {
283 assert(is_string($hook));
284
286 $config = \SimpleSAML_Configuration::getOptionalConfig()->getArray('module.enable', array());
287 sort($modules);
288 foreach ($modules as $module) {
289 if (!self::isModuleEnabledWithConf($module, $config)) {
290 continue;
291 }
292
293 if (!isset(self::$module_info[$module]['hooks'])) {
294 self::$module_info[$module]['hooks'] = self::getModuleHooks($module);
295 }
296
297 if (!isset(self::$module_info[$module]['hooks'][$hook])) {
298 continue;
299 }
300
301 require_once(self::$module_info[$module]['hooks'][$hook]['file']);
302
303 if (!is_callable(self::$module_info[$module]['hooks'][$hook]['func'])) {
304 throw new \SimpleSAML_Error_Exception('Invalid hook \''.$hook.'\' for module \''.$module.'\'.');
305 }
306
307 $fn = self::$module_info[$module]['hooks'][$hook]['func'];
308 $fn($data);
309 }
310 }
static getModuleHooks($module)
Get the available hooks for a given module.
Definition: Module.php:242
static getModules()
Get available modules.
Definition: Module.php:121
static $modules
Definition: Module.php:20
static getOptionalConfig($filename='config.php', $configSet='simplesaml')
Load a configuration file from a configuration set.
$config
Definition: bootstrap.php:15
if($modEnd===false) $module
Definition: module.php:59

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 39 of file Module.php.

40 {
41 $baseDir = dirname(dirname(dirname(__FILE__))).'/modules';
43
44 return $moduleDir;
45 }
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(), sspmod_core_Auth_Process_AttributeMap\loadMapFile(), sspmodAutoloadPSR0(), and sspmodAutoloadPSR4().

+ 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 242 of file Module.php.

243 {
244 if (isset(self::$modules[$module]['hooks'])) {
245 return self::$modules[$module]['hooks'];
246 }
247
248 $hook_dir = self::getModuleDir($module).'/hooks';
249 if (!is_dir($hook_dir)) {
250 return array();
251 }
252
253 $hooks = array();
254 $files = scandir($hook_dir);
255 foreach ($files as $file) {
256 if ($file[0] === '.') {
257 continue;
258 }
259
260 if (!preg_match('/hook_(\w+)\.php/', $file, $matches)) {
261 continue;
262 }
263 $hook_name = $matches[1];
264 $hook_func = $module.'_hook_'.$hook_name;
265 $hooks[$hook_name] = array('file' => $hook_dir.'/'.$file, 'func' => $hook_func);
266 }
267 return $hooks;
268 }
static getModuleDir($module)
Retrieve the base directory for a module.
Definition: Module.php:39
$files
Definition: metarefresh.php:49

◆ 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 121 of file Module.php.

122 {
123 if (!empty(self::$modules)) {
124 return self::$modules;
125 }
126
128
129 $dh = scandir($path);
130 if ($dh === false) {
131 throw new \Exception('Unable to open module directory "'.$path.'".');
132 }
133
134 foreach ($dh as $f) {
135 if ($f[0] === '.') {
136 continue;
137 }
138
139 if (!is_dir($path.'/'.$f)) {
140 continue;
141 }
142
143 self::$modules[] = $f;
144 }
145
146 return self::$modules;
147 }
$path
Definition: aliased.php:25

References $f, and $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 220 of file Module.php.

221 {
222 assert(is_string($resource));
223 assert($resource[0] !== '/');
224
225 $url = Utils\HTTP::getBaseURL().'module.php/'.$resource;
226 if (!empty($parameters)) {
227 $url = Utils\HTTP::addURLParameters($url, $parameters);
228 }
229 return $url;
230 }
static getBaseURL()
Retrieve the base URL of the SimpleSAMLphp installation.
Definition: HTTP.php:597
$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_core_Auth_Process_Cardinality\process(), sspmod_core_Auth_Process_CardinalitySingle\process(), 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 59 of file Module.php.

60 {
62 return self::isModuleEnabledWithConf($module, $config->getArray('module.enable', array()));
63 }
static isModuleEnabledWithConf($module, $mod_config)
Definition: Module.php:66

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 66 of file Module.php.

67 {
68 if (isset(self::$module_info[$module]['enabled'])) {
69 return self::$module_info[$module]['enabled'];
70 }
71
72 if (!empty(self::$modules) && !in_array($module, self::$modules, true)) {
73 return false;
74 }
75
77
78 if (!is_dir($moduleDir)) {
79 self::$module_info[$module]['enabled'] = false;
80 return false;
81 }
82
83 if (isset($mod_config[$module])) {
84 if (is_bool($mod_config[$module])) {
85 self::$module_info[$module]['enabled'] = $mod_config[$module];
86 return $mod_config[$module];
87 }
88
89 throw new \Exception("Invalid module.enable value for the '$module' module.");
90 }
91
92 if (assert_options(ASSERT_ACTIVE) &&
93 !file_exists($moduleDir.'/default-enable') &&
94 !file_exists($moduleDir.'/default-disable')
95 ) {
96 \SimpleSAML\Logger::error("Missing default-enable or default-disable file for the module $module");
97 }
98
99 if (file_exists($moduleDir.'/enable')) {
100 self::$module_info[$module]['enabled'] = true;
101 return true;
102 }
103
104 if (!file_exists($moduleDir.'/disable') && file_exists($moduleDir.'/default-enable')) {
105 self::$module_info[$module]['enabled'] = true;
106 return true;
107 }
108
109 self::$module_info[$module]['enabled'] = false;
110 return false;
111 }
static error($string)
Definition: Logger.php:166

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 169 of file Module.php.

170 {
171 assert(is_string($id));
172 assert(is_string($type));
173 assert(is_string($subclass) || $subclass === null);
174
175 $tmp = explode(':', $id, 2);
176 if (count($tmp) === 1) { // no module involved
177 $className = $tmp[0];
178 if (!class_exists($className)) {
179 throw new \Exception("Could not resolve '$id': no class named '$className'.");
180 }
181 } else { // should be a module
182 // make sure empty types are handled correctly
183 $type = (empty($type)) ? '_' : '_'.$type.'_';
184
185 // check for the old-style class names
186 $className = 'sspmod_'.$tmp[0].$type.$tmp[1];
187
188 if (!class_exists($className)) {
189 // check for the new-style class names, using namespaces
190 $type = str_replace('_', '\\', $type);
191 $newClassName = 'SimpleSAML\Module\\'.$tmp[0].$type.$tmp[1];
192
193 if (!class_exists($newClassName)) {
194 throw new \Exception("Could not resolve '$id': no class named '$className' or '$newClassName'.");
195 }
196 $className = $newClassName;
197 }
198 }
199
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.'\'.'
203 );
204 }
205
206 return $className;
207 }
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
if(!array_key_exists('StateId', $_REQUEST)) $id
$type

References $id, $type, and if.

Referenced by SimpleSAML_Stats\createOutput(), sspmod_statistics_StatDataset\getDelimiterPresentation(), sspmod_statistics_Ruleset\getRule(), SimpleSAML_Metadata_MetaDataStorageSource\getSource(), 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: