1 <?php 2 3 /** 4 * Autoloader Class 5 * 6 * PHP Version 5 7 * 8 * @file CAS/Autoload.php 9 * @category Authentication 10 * @package SimpleCAS 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/ 15 **/ 16 17 /** 18 * Autoload a class 19 * 20 * @param string $class Classname to load 21 * 22 * @return bool 23 */ 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 (!(spl_autoload_functions()) 78 || !in_array('CAS_autoload', spl_autoload_functions()) 79 ) { 80 spl_autoload_register('CAS_autoload'); 81 if (function_exists('__autoload') 82 && !in_array('__autoload', spl_autoload_functions()) 83 ) { 84 // __autoload() was being used, but now would be ignored, add 85 // it to the autoload stack 86 spl_autoload_register('__autoload'); 87 } 88 } 89 90 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body