phpCAS  version 1.4.0
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_' && substr($class, 0, 7) !== 'PhpCas\\') {
30  return false;
31  }
32 
33  // Setup the include path if it's not already set from a previous call
34  if (empty($include_path)) {
35  $include_path = array(dirname(__DIR__));
36  }
37 
38  // Declare local variable to store the expected full path to the file
39  foreach ($include_path as $path) {
40  $class_path = str_replace('_', DIRECTORY_SEPARATOR, $class);
41  // PhpCas namespace mapping
42  if (substr($class_path, 0, 7) === 'PhpCas\\') {
43  $class_path = 'CAS' . DIRECTORY_SEPARATOR . substr($class_path, 7);
44  }
45 
46  $file_path = $path . DIRECTORY_SEPARATOR . $class_path . '.php';
47  $fp = @fopen($file_path, 'r', true);
48  if ($fp) {
49  fclose($fp);
50  include $file_path;
51  if (!class_exists($class, false) && !interface_exists($class, false)) {
52  die(
53  new Exception(
54  'Class ' . $class . ' was not present in ' .
55  $file_path .
56  ' [CAS_autoload]'
57  )
58  );
59  }
60  return true;
61  }
62  }
63 
64  $e = new Exception(
65  'Class ' . $class . ' could not be loaded from ' .
66  $file_path . ', file does not exist (Path="'
67  . implode(':', $include_path) .'") [CAS_autoload]'
68  );
69  $trace = $e->getTrace();
70  if (isset($trace[2]) && isset($trace[2]['function'])
71  && in_array($trace[2]['function'], array('class_exists', 'interface_exists'))
72  ) {
73  return false;
74  }
75  if (isset($trace[1]) && isset($trace[1]['function'])
76  && in_array($trace[1]['function'], array('class_exists', 'interface_exists'))
77  ) {
78  return false;
79  }
80  die ((string) $e);
81 }
82 
83 // Set up autoload if not already configured by composer.
84 if (!class_exists('CAS_Client'))
85 {
86  trigger_error('phpCAS autoloader is deprecated. Install phpCAS using composer instead.', E_USER_DEPRECATED);
87  spl_autoload_register('CAS_autoload');
88  if (function_exists('__autoload')
89  && !in_array('__autoload', spl_autoload_functions())
90  ) {
91  // __autoload() was being used, but now would be ignored, add
92  // it to the autoload stack
93  spl_autoload_register('__autoload');
94  }
95 }
CAS_autoload($class)
Definition: Autoload.php:24