Project

General

Profile

1
<?php
2
/* 
3
 * To change this template, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6

    
7
class WbAutoloader
8
{
9

    
10
	static private $_aSearchpatterns = array();
11
	static private $_aReplacements = array();
12

    
13
/**
14
 * Register WB - CoreAutoloader as SPL autoloader
15
 * @param array $aDirectories list of 'directory'=>'shortKey'
16
 */
17
    static public function doRegister(array $aDirectories)
18
    {
19
		if(sizeof($aDirectories > 0)) {
20
			self::$_aSearchpatterns[] = '/(^.[^_].*$)/i';
21
			self::$_aReplacements[] = basename(dirname(__FILE__)).'_$1';
22
			foreach($aDirectories as $value => $shortKey) {
23
				self::$_aSearchpatterns[] = '/^'.$shortKey.'_/i';
24
				self::$_aReplacements[] = $value.'_';
25
			}
26
		}
27
        spl_autoload_register(array(new self, 'CoreAutoloader'));
28
    }
29
/**
30
 * tries autoloading the given class
31
 * @param  string $sClassName
32
 */
33
	static public function CoreAutoloader($sClassName)
34
	{
35
		if($sClassName == 'database'){
36
			$sFileName = dirname(__FILE__).'/class.database.php';
37
			if(is_file($sFileName)) { include($sFileName); }
38
		}else {
39
			$sClassName = preg_replace(self::$_aSearchpatterns, self::$_aReplacements, $sClassName);
40
			$sFileName = dirname(dirname(__FILE__)).'/'.str_replace('_', '/', $sClassName).'.php';
41
			if(is_file($sFileName = dirname(dirname(__FILE__)).'/'.str_replace('_', '/', $sClassName).'.php')) {
42
				include($sFileName);
43
			}
44
		}
45
	}
46
} // end class Autoloader
(11-11/29)