ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
_autoload_modules.php File Reference

Go to the source code of this file.

Namespaces

 SimpleSAMLphp
 Temporary autoloader to ensure compatibility with old, non-PSR-2 compliant classes.
 

Functions

 temporaryLoader ($class)
 This temporary autoloader allows loading classes with their old-style names (SimpleSAML_Path_Something) even if they have been migrated to namespaces, by registering an alias for the new class. More...
 
 sspmodAutoloadPSR0 ($className)
 Autoload function for SimpleSAMLphp modules following PSR-0. More...
 
 sspmodAutoloadPSR4 ($className)
 Autoload function for SimpleSAMLphp modules following PSR-4. More...
 

Function Documentation

◆ sspmodAutoloadPSR0()

sspmodAutoloadPSR0 (   $className)

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 82 of file _autoload_modules.php.

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

83 {
84  $modulePrefixLength = strlen('sspmod_');
85  $classPrefix = substr($className, 0, $modulePrefixLength);
86  if ($classPrefix !== 'sspmod_') {
87  return;
88  }
89 
90  $modNameEnd = strpos($className, '_', $modulePrefixLength);
91  $module = substr($className, $modulePrefixLength, $modNameEnd - $modulePrefixLength);
92  $path = explode('_', substr($className, $modNameEnd + 1));
93 
94  if (!\SimpleSAML\Module::isModuleEnabled($module)) {
95  return;
96  }
97 
98  $file = \SimpleSAML\Module::getModuleDir($module).'/lib/'.join('/', $path).'.php';
99  if (!file_exists($file)) {
100  return;
101  }
102  require_once($file);
103 
104  if (!class_exists($className, false) && !interface_exists($className, false)) {
105  // the file exists, but the class is not defined. Is it using namespaces?
106  $nspath = join('\\', $path);
107  if (class_exists('SimpleSAML\Module\\'.$module.'\\'.$nspath) ||
108  interface_exists('SimpleSAML\Module\\'.$module.'\\'.$nspath)
109  ) {
110  // the class has been migrated, create an alias and warn about it
112  "The class or interface '$className' is now using namespaces, please use 'SimpleSAML\\Module\\".
113  $module."\\".$nspath."' instead."
114  );
115  class_alias("SimpleSAML\\Module\\$module\\$nspath", $className);
116  }
117  }
118 }
$path
Definition: aliased.php:25
static getModuleDir($module)
Retrieve the base directory for a module.
Definition: Module.php:39
if($modEnd===false) $module
Definition: module.php:59
Attribute-related utility methods.
static warning($string)
Definition: Logger.php:177
+ Here is the call graph for this function:

◆ sspmodAutoloadPSR4()

sspmodAutoloadPSR4 (   $className)

Autoload function for SimpleSAMLphp modules following PSR-4.

Parameters
string$classNameName of the class.

Definition at line 126 of file _autoload_modules.php.

References $module, and SimpleSAML\Module\getModuleDir().

127 {
128  $elements = explode('\\', $className);
129  if ($elements[0] === '') { // class name starting with /, ignore
130  array_shift($elements);
131  }
132  if (count($elements) < 4) {
133  return; // it can't be a module
134  }
135  if (array_shift($elements) !== 'SimpleSAML') {
136  return; // the first element is not "SimpleSAML"
137  }
138  if (array_shift($elements) !== 'Module') {
139  return; // the second element is not "module"
140  }
141 
142  // this is a SimpleSAMLphp module following PSR-4
143  $module = array_shift($elements);
144  if (!\SimpleSAML\Module::isModuleEnabled($module)) {
145  return; // module not enabled, avoid giving out any information at all
146  }
147 
148  $file = \SimpleSAML\Module::getModuleDir($module).'/lib/'.implode('/', $elements).'.php';
149 
150  if (file_exists($file)) {
151  require_once($file);
152  }
153 }
static getModuleDir($module)
Retrieve the base directory for a module.
Definition: Module.php:39
if($modEnd===false) $module
Definition: module.php:59
Attribute-related utility methods.
+ Here is the call graph for this function:

◆ temporaryLoader()

temporaryLoader (   $class)

This temporary autoloader allows loading classes with their old-style names (SimpleSAML_Path_Something) even if they have been migrated to namespaces, by registering an alias for the new class.

If the class has not yet been migrated, the autoloader will then try to load it.

Parameters
string$classThe full name of the class using underscores to separate the elements of the path, and starting with 'SimpleSAML_'.
Deprecated:
This function will be removed in SSP 2.0.

Definition at line 20 of file _autoload_modules.php.

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

21 {
22  // handle the upgrade to the latest version of XMLSecLibs using namespaces
23  if (strstr($class, 'XMLSec')) {
24  if (class_exists('\\RobRichards\\XMLSecLibs\\'.$class, true)) {
25  class_alias('\\RobRichards\\XMLSecLibs\\'.$class, $class);
26  return;
27  }
28  }
29 
30  if (!strstr($class, 'SimpleSAML_')) {
31  return; // not a valid class name for old classes
32  }
33  $original = $class;
34 
35  // list of classes that have been renamed or moved
36  $renamed = array(
37  'SimpleSAML_Metadata_MetaDataStorageHandlerMDX' => 'SimpleSAML_Metadata_Sources_MDQ',
38  'SimpleSAML_Logger_LoggingHandlerSyslog' => 'SimpleSAML_Logger_SyslogLoggingHandler',
39  'SimpleSAML_Logger_LoggingHandlerErrorLog' => 'SimpleSAML_Logger_ErrorLogLoggingHandler',
40  'SimpleSAML_Logger_LoggingHandlerFile' => 'SimpleSAML_Logger_FileLoggingHandler',
41  'SimpleSAML_Logger_LoggingHandler' => 'SimpleSAML_Logger_LoggingHandlerInterface',
42  'SimpleSAML_IdP_LogoutHandler' => 'SimpleSAML_IdP_LogoutHandlerInterface',
43  'SimpleSAML_IdP_LogoutIFrame' => 'SimpleSAML_IdP_IFrameLogoutHandler',
44  'SimpleSAML_IdP_LogoutTraditional' => 'SimpleSAML_IdP_TraditionalLogoutHandler',
45  );
46  if (array_key_exists($class, $renamed)) {
47  // the class has been renamed, try to load it and create an alias
48  $class = $renamed[$class];
49  }
50 
51  // try to load it from the corresponding file
52  $path = explode('_', $class);
53  $file = dirname(__FILE__).DIRECTORY_SEPARATOR.join(DIRECTORY_SEPARATOR, $path).'.php';
54  if (file_exists($file)) {
55  require_once $file;
56  }
57 
58  // it exists, so it's not yet migrated to namespaces
59  if (class_exists($class, false) || interface_exists($class, false)) {
60  return;
61  }
62 
63  // it didn't exist, try to see if it was migrated to namespaces
64  $new = join('\\', $path);
65  if (class_exists($new, false) || interface_exists($new, false)) {
66  // do not try to autoload it if it doesn't exist! It should!
67  class_alias($new, $original);
68  SimpleSAML\Logger::warning("The class or interface '$original' is now using namespaces, please use '$new'.");
69  }
70 }
$path
Definition: aliased.php:25
static warning($string)
Definition: Logger.php:177
+ Here is the call graph for this function: