ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Autoload.php
Go to the documentation of this file.
1 <?php
2 
24 function CAS_autoload($class)
25 {
26  // Static to hold the Include Path to CAS
27  static $include_path;
28  // Check only for CAS classes
29  if (substr($class, 0, 4) !== 'CAS_') {
30  return false;
31  }
32  // Setup the include path if it's not already set from a previous call
33  if (empty($include_path)) {
34  $include_path = array(dirname(dirname(__FILE__)), dirname(dirname(__FILE__)) . '/../test/' );
35  }
36 
37  // Declare local variable to store the expected full path to the file
38 
39  foreach ($include_path as $path) {
40  $file_path = $path . '/' . str_replace('_', '/', $class) . '.php';
41  $fp = @fopen($file_path, 'r', true);
42  if ($fp) {
43  fclose($fp);
44  include $file_path;
45  if (!class_exists($class, false) && !interface_exists($class, false)) {
46  die(
47  new Exception(
48  'Class ' . $class . ' was not present in ' .
49  $file_path .
50  ' [CAS_autoload]'
51  )
52  );
53  }
54  return true;
55  }
56  }
57  $e = new Exception(
58  'Class ' . $class . ' could not be loaded from ' .
59  $file_path . ', file does not exist (Path="'
60  . implode(':', $include_path) .'") [CAS_autoload]'
61  );
62  $trace = $e->getTrace();
63  if (isset($trace[2]) && isset($trace[2]['function'])
64  && in_array($trace[2]['function'], array('class_exists', 'interface_exists'))
65  ) {
66  return false;
67  }
68  if (isset($trace[1]) && isset($trace[1]['function'])
69  && in_array($trace[1]['function'], array('class_exists', 'interface_exists'))
70  ) {
71  return false;
72  }
73  die ((string) $e);
74 }
75 
76 // set up __autoload
77 if (function_exists('spl_autoload_register')) {
78  if (!(spl_autoload_functions())
79  || !in_array('CAS_autoload', spl_autoload_functions())
80  ) {
81  spl_autoload_register('CAS_autoload');
82  if (function_exists('__autoload')
83  && !in_array('__autoload', spl_autoload_functions())
84  ) {
85  // __autoload() was being used, but now would be ignored, add
86  // it to the autoload stack
87  spl_autoload_register('__autoload');
88  }
89  }
90 } elseif (!function_exists('__autoload')) {
91 
99  function __autoload($class)
100  {
101  return CAS_autoload($class);
102  }
103 }
104 
105 ?>
$path
Definition: aliased.php:25
CAS_autoload($class)
Autoload a class.
Definition: Autoload.php:24
Create styles array
The data for the language used.