1 |
1686
|
darkviper
|
<?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 |
1870
|
Luisehahne
|
static public function doRegister(array $aDirectories)
|
18 |
|
|
{
|
19 |
2010
|
darkviper
|
if(!sizeof(self::$_aSearchpatterns))
|
20 |
|
|
{
|
21 |
|
|
if(sizeof($aDirectories > 0))
|
22 |
|
|
{
|
23 |
1870
|
Luisehahne
|
self::$_aSearchpatterns[] = '/(^.[^_].*$)/i';
|
24 |
2010
|
darkviper
|
self::$_aReplacements[] = basename(dirname(__FILE__)).'_\1';
|
25 |
|
|
foreach($aDirectories as $value => $shortKey)
|
26 |
|
|
{
|
27 |
1870
|
Luisehahne
|
self::$_aSearchpatterns[] = '/^'.$shortKey.'_/i';
|
28 |
|
|
self::$_aReplacements[] = $value.'_';
|
29 |
|
|
}
|
30 |
1686
|
darkviper
|
}
|
31 |
|
|
}
|
32 |
1870
|
Luisehahne
|
spl_autoload_register(array(new self, 'CoreAutoloader'));
|
33 |
|
|
}
|
34 |
1686
|
darkviper
|
/**
|
35 |
|
|
* tries autoloading the given class
|
36 |
|
|
* @param string $sClassName
|
37 |
|
|
*/
|
38 |
|
|
static public function CoreAutoloader($sClassName)
|
39 |
|
|
{
|
40 |
2010
|
darkviper
|
$sClassName = preg_replace(self::$_aSearchpatterns, self::$_aReplacements, $sClassName);
|
41 |
|
|
$sFileName = dirname(dirname(__FILE__)).'/'.str_replace('_', '/', $sClassName).'.php';
|
42 |
|
|
if (!is_file($sFileName = dirname(dirname(__FILE__)).'/'.str_replace('_', '/', $sClassName).'.php')) {
|
43 |
|
|
// alternatively search for file with prefix 'class.'
|
44 |
|
|
if (!is_file(($sFileName = dirname($sFileName).'/class.'.basename($sFileName)))) {
|
45 |
|
|
return false;
|
46 |
1689
|
darkviper
|
}
|
47 |
1686
|
darkviper
|
}
|
48 |
2010
|
darkviper
|
include($sFileName);
|
49 |
1686
|
darkviper
|
}
|
50 |
|
|
} // end class Autoloader
|