forked from mercuryphp/framework
/
index.php
68 lines (51 loc) · 1.92 KB
/
index.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
<?php
if(!ob_get_level()){
ob_start();
}
$rootPath = str_replace('\\', '/', dirname(__FILE__));
$envClassFile = $rootPath .'/System/Std/Environment.php';
require $envClassFile;
\System\Std\Environment::addClassFile($envClassFile);
set_error_handler(function($errno, $errstr, $errfile, $errline){
throw new \ErrorException($errstr, $errno, 0, $errfile, $errline);
});
spl_autoload_register(function($class){
$path = str_replace('\\', '/', dirname(__FILE__));
$file = classFile($path, $class);
if (is_file($file)){
\System\Std\Environment::addClassFile($file);
require $file;
}else{
$namespaces = \System\Std\Environment::getNamespaces();
$namespaceClass = '';
$segments = explode('\\',$class);
$class = array_pop($segments);
if(isset($namespaces[$class])){
$namespaceClass = $namespaces[$class];
}
$file = classFile($path, $namespaceClass);
if(is_file($file)){
if(!\System\Std\Environment::hasClassFile($file)){
require $file;
}
class_alias(str_replace('.', '\\', $namespaceClass), $class);
}
}
});
function classFile($path, $class){
$namespacePath = str_replace(array('\\', '.'), '/', $class);
$file = $path . '/' . $namespacePath . '.php';
return $file;
}
require $rootPath . '/global.php';
$mvcApplication = new MvcApplication($rootPath);
try {
$mvcApplication->start();
$mvcApplication->init();
$mvcApplication->load();
$mvcApplication->run();
$mvcApplication->end();
}catch(\Exception $e){
$mvcApplication->error($e);
}
?>