1<?php 2 3 4gtAutoload::init(); 5 6/** 7 * Autoloader using a map file (gtClassMap.php) 8 * defining the file to load each class from. 9 */ 10class gtAutoload 11{ 12 /** 13 * @var array 14 */ 15 protected static $classMap; 16 17 /** 18 * @var string 19 */ 20 protected static $classPath; 21 22 23 /** 24 * Initialize the autoloader 25 * 26 * @return null 27 */ 28 public static function init() 29 { 30 self::$classPath = dirname(__FILE__); 31 32 if (substr(self::$classPath, -1) != '/') { 33 self::$classPath .= '/'; 34 } 35 36 if (file_exists(self::$classPath . 'gtClassMap.php')) { 37 include self::$classPath . 'gtClassMap.php'; 38 self::$classMap = $gtClassMap; 39 } 40 41 if (function_exists('__autoload')) { 42 spl_autoload_register('__autoload'); 43 } 44 45 spl_autoload_register(array('gtAutoload', 'autoload')); 46 } 47 48 49 /** 50 * Autoload method 51 * 52 * @param string $class Class name to autoload 53 * @return null 54 */ 55 public static function autoload($class) 56 { 57 if (isset(self::$classMap[$class])) { 58 include self::$classPath . self::$classMap[$class]; 59 } 60 } 61} 62 63?>