Alternc  3.2
Alternc logiel libre pour l'h├ębergement
 All Data Structures Namespaces Files Functions Variables Pages
AutoLoader.php
Go to the documentation of this file.
1 <?php
2 class AutoLoader {
3 
4  static private $classNames = array();
5 
6  /**
7  * Store the filename (sans extension) & full path of all ".php" files found
8  */
9  public static function registerDirectory($dirName) {
10 
11  $di = new DirectoryIterator($dirName);
12  foreach ($di as $file) {
13 
14  if ($file->isDir() && !$file->isLink() && !$file->isDot()) {
15  // recurse into directories other than a few special ones
16  self::registerDirectory($file->getPathname());
17  } elseif (substr($file->getFilename(), -4) === '.php') {
18  // save the class name / path of a .php file found
19  $className = substr($file->getFilename(), 0, -4);
20  AutoLoader::registerClass($className, $file->getPathname());
21  }
22  }
23  }
24 
25  public static function registerClass($className, $fileName) {
26  AutoLoader::$classNames[$className] = $fileName;
27  }
28 
29  public static function loadClass($className) {
30  if (isset(AutoLoader::$classNames[$className])) {
31  require_once(AutoLoader::$classNames[$className]);
32  }
33  }
34 
35 }
36 
37 spl_autoload_register(array('AutoLoader', 'loadClass'));