8 * @file CAS/Autoload.php
9 * @category Authentication
11 * @author Brett Bieber <brett.bieber@gmail.com>
12 * @copyright 2008 Regents of the University of Nebraska
13 * @license http://www1.unl.edu/wdn/wiki/Software_License BSD License
14 * @link http://code.google.com/p/simplecas/
20 * @param string $class Classname to load
24 function CAS_autoload($class)
26 // Static to hold the Include Path to CAS
28 // Setup the include path if it's not already set from a previous call
30 $include_path = dirname(dirname(__FILE__));
32 if (substr($class, 0, 4) !== 'CAS_') {
35 // Declare local variable to store the expected full path to the file
36 $file_path = $include_path . '/' . str_replace('_', '/', $class) . '.php';
38 $fp = @fopen($file_path, 'r', true);
42 if (!class_exists($class, false) && !interface_exists($class, false)) {
45 'Class ' . $class . ' was not present in ' .
54 'Class ' . $class . ' could not be loaded from ' .
55 $file_path . ', file does not exist (Path="'
56 . $include_path .'") [CAS_autoload]'
58 $trace = $e->getTrace();
59 if (isset($trace[2]) && isset($trace[2]['function'])
60 && in_array($trace[2]['function'], array('class_exists', 'interface_exists'))
64 if (isset($trace[1]) && isset($trace[1]['function'])
65 && in_array($trace[1]['function'], array('class_exists', 'interface_exists'))
73 if (function_exists('spl_autoload_register')) {
74 if (!(spl_autoload_functions()) || !in_array('CAS_autoload', spl_autoload_functions())) {
75 spl_autoload_register('CAS_autoload');
76 if (function_exists('__autoload') && !in_array('__autoload', spl_autoload_functions())) {
77 // __autoload() was being used, but now would be ignored, add
78 // it to the autoload stack
79 spl_autoload_register('__autoload');
82 } elseif (!function_exists('__autoload')) {
87 * @param string $class Class name
91 function __autoload($class)
93 return CAS_autoload($class);