-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoader.php
executable file
·52 lines (36 loc) · 1.33 KB
/
Loader.php
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
<?php
class Core_Loader{
static protected $instance;
static public function autoload( $class ){
$path = "";
$classLen = strlen($class);
if(substr($class, 0, 5) == 'Core_'){
$path = CORE_PATH . "/" . str_replace("_", "/", substr($class, 5));
}elseif(substr($class, $classLen - 10) == 'Controller'){
$path = APP_PATH . "/controllers/" . str_replace("_", "/", substr($class, 0, $classLen - 10));
}elseif(substr($class, $classLen - 5) == 'Model'){
$path = APP_PATH . "/models/" . str_replace("_", "/", substr($class, 0, $classLen - 5));
}elseif(substr($class, $classLen - 6) == 'Widget'){
$path = APP_PATH . "/widget/" . str_replace("_", "/", substr($class, 0, $classLen - 6));
}else{
$path = APP_PATH . "/library/" . str_replace("_", "/", $class);
}
$path .= ".php";
if(file_exists($path)){
include_once $path;
}else{
throw new Core_Exception("include file not exists: {$path}");
}
}
static public function getInstance( $class , $param = '' ){
if( !isset(self::$instance[$class]) || self::$instance[$class] == '' ){
if(empty($param)){
self::$instance[$class] = new $class();
}else{
self::$instance[$class] = new $class( $param );
}
}
return self::$instance[$class];
}
}
?>