Repository navigation
Expand file tree
/
Copy pathframework.php
More file actions
155 lines (145 loc) · 4.68 KB
/
Copy pathframework.php
File metadata and controls
155 lines (145 loc) · 4.68 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
if(!isset($_SESSION)){
session_start();
}
class Core {
private static $_instance = array();
private static $classFile;
private function __construct(){
//-----------需要页面显示调试信息, 注释掉下面两行即可---
//-------------------------------------------------------
set_error_handler(array("Core",'appError'));
set_exception_handler(array("Core",'appException'));
date_default_timezone_set("Asia/Shanghai");
if(version_compare(PHP_VERSION,'5.4.0','<') ) {
@set_magic_quotes_runtime (0);
define('MAGIC_QUOTES_GPC',get_magic_quotes_gpc()?True:False);
}
if(!defined('WEB_PATH')){
define("WEB_PATH", "E:/PHP/news_manage/");
}
include WEB_PATH."lib/common.php"; //此文件定义了C函数
//加载全局配置信息
C(include WEB_PATH.'conf/common.php');
include WEB_PATH."lib/log.php"; //日志类
include WEB_PATH."lib/page.php"; //分页类
//加载数据接口层及所需支撑
include WEB_PATH."lib/service/http.php"; //网络接口
include WEB_PATH."lib/functions.php"; //公共方法
include WEB_PATH."lib/cache/cache.php"; //memcache
//加载语言包
$lang = WEB_PATH."lang/".C("LANG").".php"; //memcache
if(file_exists($lang)){
C(include $lang);
}
if(C("DATAGATE") == "db"){
$db = C("DB_TYPE");
include WEB_PATH."lib/db/".$db.".php"; //db直连
if($db == "mysql"){
global $dbConn;
$db_config = C("DB_CONFIG");
$dbConn = new mysql();
$dbConn->connect($db_config["master1"][0],$db_config["master1"][1],$db_config["master1"][2]);
$dbConn->select_db($db_config["master1"][4]);
}
if(C("DB_TYPE") == "mongodb"){
//.......
}
}
//自动加载类
spl_autoload_register(array('Core', 'autoload'));
}
//自动加载实现
public function autoload($class){
//加载act
if(strpos($class,"Act")){
$name = preg_replace("/Act/","",$class);
$fileName = lcfirst($name).".action.php";
Core::getFile($fileName,WEB_PATH."action/");
if(empty(Core::$classFile)){
throw new Exception("action no exits");
}
include_once Core::$classFile;
}
if(strpos($class,"Model")){
$name = preg_replace("/Model/","",$class);
$fileName = lcfirst($name).".model.php";
Core::getFile($fileName,WEB_PATH."model/");
if(empty(Core::$classFile)){
throw new Exception("action no exits");
}
include_once Core::$classFile;
}
if(strpos($class,"View")){
$name = preg_replace("/View/","",$class);
$fileName = lcfirst($name).".view.php";
Core::getFile($fileName,WEB_PATH."view/");
if(empty(Core::$classFile)){
throw new Exception("action no exits");
}
include_once Core::$classFile;
}
}
public static function getFile($fileName,$path){
if ($handle = @opendir($path)) {
while(false !== ($file = @readdir($handle))) {
if(is_dir($path.$file) && ($file != "." && $file != "..")){
Core::getFile($fileName,$path.$file."/");
}else{
if($file==$fileName){
Core::$classFile = $path.$file;
}
}
}
}
@closedir($handle);
}
private function __clone() {}
//单实例
public static function getInstance(){
if(!(self::$_instance instanceof self)){
self::$_instance = new self();
}
return self::$_instance;
}
/**
+----------------------------------------------------------
* 自定义异常处理
* @access public
* @param mixed $e 异常对象
*/
static public function appException($e) {
echo $e;
}
/**
+----------------------------------------------------------
* 自定义错误处理
* @access public
* @param int $errno 错误类型
* @param string $errstr 错误信息
* @param string $errfile 错误文件
* @param int $errline 错误行数
* @return void
+----------------------------------------------------------
*/
static public function appError($errno, $errstr, $errfile, $errline) {
switch ($errno) {
case E_WARNING:
$errorStr = "[$errno] $errstr ".basename($errfile)." 第 $errline 行.";
if(C('LOG_RECORD')) Log::write($errorStr,Log::ERR);
break;
case E_ERROR:
case E_USER_ERROR:
$errorStr = "[$errno] $errstr ".basename($errfile)." 第 $errline 行.";
if(C('LOG_RECORD')) Log::write($errorStr,Log::ERR);
break;
case E_STRICT:
case E_USER_WARNING:
case E_USER_NOTICE:
default:
$errorStr = "[$errno] $errstr ".basename($errfile)." 第 $errline 行.";
Log::record($errorStr,Log::NOTICE);
break;
}
}
}