gtAutoload.php 1.1 KB

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