summaryrefslogtreecommitdiff
path: root/scripts/dev/generate-phpt/src/gtAutoload.php
blob: 8c18c179eb2cb94edcbaa1530573343eab36d47f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php


gtAutoload::init();

/**
 * Autoloader using a map file (gtClassMap.php)
 * defining the file to load each class from.
 */
class gtAutoload
{
  /**
   * @var array
   */
  protected static $classMap;

  /**
   * @var string
   */
  protected static $classPath;


  /**
   * Initialize the autoloader
   *
   * @return null
   */
  public static function init()
  {
    self::$classPath = dirname(__FILE__);

    if (substr(self::$classPath, -1) != '/') {
      self::$classPath .= '/';
    }

    if (file_exists(self::$classPath . 'gtClassMap.php')) {
      include self::$classPath . 'gtClassMap.php';
      self::$classMap = $gtClassMap;
    }

    if (function_exists('__autoload')) {
      spl_autoload_register('__autoload');
    }

    spl_autoload_register(array('gtAutoload', 'autoload'));
  }


  /**
   * Autoload method
   *
   * @param string $class Class name to autoload
   * @return null
   */
  public static function autoload($class)
  {
    if (isset(self::$classMap[$class])) {
      include self::$classPath . self::$classMap[$class];
    }
  }
}

?>