Repository navigation
Expand file tree
/
Copy pathWpf_Loader.php
More file actions
55 lines (47 loc) · 1.47 KB
/
Copy pathWpf_Loader.php
File metadata and controls
55 lines (47 loc) · 1.47 KB
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
<?php
class Wpf_Autoloader {
public $pathList = array();
public function __construct() {
$this->pathList = array();
}
private $registedClasses = array();
public function registerClass(array $classAndPath) {
$this->registedClasses = $classAndPath;
}
public function addDir($dir) {
$this->pathList[] = $dir;
}
public function addNamedDir($name, $dir) {
$this->pathList[$name] = $dir;
}
public function classNameToPath($className) {
$path = '';
$lastpos = strrpos($className, "_");
if (false !== $lastpos) {
$path = '/' . str_replace('_', '/', substr($className, 0, $lastpos));
}
$lastpos = strrpos($className, "\\");
if (false !== $lastpos) {
$classNameArr = explode("\\", $className);
$className = array_pop($classNameArr);
$path = join("/", $classNameArr);
}
return "{$path}/{$className}.php";
}
public function load($className) {
$classNamePath = "";
if (isset($this->registedClasses[$className])) {
$classNamePath = WPF_LIB_DIR . "/../" . $this->registedClasses[$className];
} else {
$classNamePath = $this->classNameToPath($className);
foreach ($this->pathList as $dir) {
$tmppath = $dir . $classNamePath;
if (file_exists($tmppath)) {
$classNamePath = $tmppath;
break;
}
}
}
require_once ($classNamePath);
}
}