-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathN8.php
106 lines (96 loc) · 2.24 KB
/
N8.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
<?php
/**
* n8初始化程序文件
*
* @author soone(fengyue15#163.com)
*/
define('VERSION', 'v0.0.1');
define('N8_ROOT', dirname(__FILE__) . '/');
require_once N8_ROOT . './Exception.php';
final class N8
{
public $conf = '';
public function __construct()
{
spl_autoload_register(array(__CLASS__, '__autoload'));
}
/**
* __autoload
*
* @static
* @access public
* @return void
*/
public static function __autoload($cName)
{
if(class_exists($cName, false))
return;
$className = ltrim($cName, '\\');
$splFuncs = count(spl_autoload_functions());
$classPath = str_replace('_', DIRECTORY_SEPARATOR, $className . '.php');
if(file_exists($fullPath = PROJECT_ROOT . $classPath) || file_exists($fullPath = N8_ROOT . substr($classPath, 3)) )
require $fullPath;
elseif($splFuncs == 1)
throw new N8_Exception('The class ' . $cName . ' not exists', 280);
if(!class_exists($cName, false) && !interface_exists($cName, false) && $splFuncs == 1)
throw new N8_Exception('The class ' . $cName . ' not exists', 290);
}
/**
* n8初始化以及项目的初始化
*
* @access public
* @return void
*/
public function init()
{
if(!RELEASE)
{
define('PROJECT_CONFIG', PROJECT_ROOT . './Config');
$disErr = 1;
$errLevel = 7;
}
else
{
define('PROJECT_CONFIG', PROJECT_ROOT . './Cache/Config');
$disErr = 0;
$errLevel = 0;
}
ini_set('display_errors', $disErr);
ini_set('error_reporting', $errLevel);
try
{
require_once N8_ROOT . './Config.php';
$this->conf = new N8_Config(PROJECT_CONFIG . DIRECTORY_SEPARATOR . PROJECT_NAME . '.php');
}
catch(N8_Exception $e)
{
$e->n8catch();
}
return $this;
}
/**
* N8引擎启动
*
* @access public
* @return void
*/
public function run()
{
try
{
//路由解析
require N8_ROOT . './Router/Router.php';
$router = new N8_Router_Router($this->conf);
$router->parse();
$control = $router->getControl();
$action = $router->getAction();
$c = new $control($this->conf, $router->getRequest());
call_user_func(array($c, $action));
}
catch(N8_Exception $e)
{
$e->n8catch();
}
}
}
//set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(__FILE__)));