-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.php
136 lines (122 loc) · 2.17 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* 装载类
*
* @author linln
* @version $Id$
*/
class Loader
{
static public function loadClass($name)
{
if (preg_match("/^[a-zA-Z0-9]+$/i", $name))
{
include_once(strtolower($name).'.php');
}
else
{
throw new Exception('装载文件失败');
}
}
/**
* 装载DSN
*/
static public function dsn()
{
$path = CONFIG_DIR .DS. 'database.php';
if (file_exists($path))
{
include($path);
return $dsns;
}
return null;
}
/**
* 装载路由表
*/
static public function route()
{
$path = CONFIG_DIR .DS. 'router.php';
if (file_exists($path))
{
include_once($path);
return isset($routes) ? $routes : array();
}
return null;
}
/**
* 装载DBO
*
* @param string $name - DBO名称
* @return object | null
*/
static public function dbo($name)
{
// 检查文件是否存在
$dbo_file = FRAMEWORK_DIR .DS. 'Db' .DS. 'dbo_' . $name . '.php';
if (!file_exists($dbo_file))
{
return null;
}
include_once($dbo_file);
$dbo_class = 'Dbo_' . $name;
return $dbo_class;
//include_once(FRAMEWORK_DIR .DS. 'Db' .DS. 'dbo.php');
}
/**
* 装载框架中的类库
*
* @param string $name - 类库名称
*/
static public function library($name)
{
$file = FRAMEWORK_DIR .DS. 'Library' .DS. ucfirst($name) . '.class.php';
if (file_exists($file))
{
include_once($file);
}
}
/**
* 装载应用程序中的类库
*
* @param string $name
*/
static public function lib($name)
{
$file = LIBRARY_DIR .DS. strtolower($name) . '.lib.php';
if (file_exists($file))
{
include_once($file);
}
}
static public function controller($name)
{
$file = CONTROLLER_DIR .DS. strtolower($name) . '.php';
if (file_exists($file))
{
include_once($file);
}
else
{
self::exception('notfind');
throw new NotFindException();
}
}
static public function exception($name)
{
$file = FRAMEWORK_DIR .DS. 'Exception' .DS. $name . '.php';
if (file_exists($file))
{
include_once($file);
}
}
static public function config($name)
{
$file = CONFIG_DIR .DS. $name . '.php';
if (file_exists($file))
{
return(include($file));
}
}
}
?>