forked from 17mon/LookingGlass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
101 lines (81 loc) · 2.2 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
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
<?php
/**
* @bootstrap.css http://cdn.staticfile.org/twitter-bootstrap/3.1.1/css/bootstrap.min.css http://cdn.staticfile.org/twitter-bootstrap/3.1.1/css/bootstrap-theme.min.css
* @bootstrap.js http://cdn.staticfile.org/twitter-bootstrap/3.1.1/js/bootstrap.min.js
*/
class Application
{
public static function run()
{
self::registerAutoload();
self::initRequest();
self::dispatch();
}
private static function initRequest()
{
$request_uri = $_SERVER['REQUEST_URI'];
$url = parse_url($request_uri);
if (isset($url['path']))
{
$_SERVER['SCRIPT_NAME'] = $url['path'];
}
if (isset($url['query']))
{
$_SERVER['QUERY_STRING'] = $url['query'];
parse_str($url['query'], $_GET);
}
}
public static function getConfig()
{
static $config;
if (is_null($config))
{
$config = include __DIR__ . '/config.php';
}
return $config;
}
public static function dispatch()
{
$uri = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : '/';
$act = trim($uri, '/');
require_once __DIR__ . '/actions.php';
if ($act == 'execute')
{
actions::execute();
}
else
{
ob_start();
$conf = self::getConfig();
extract($conf);
include __DIR__ . '/template.phtml';
echo ob_get_clean();
}
}
public static function h($str)
{
echo htmlspecialchars($str);
}
public static function registerAutoload()
{
spl_autoload_register(function($class){
if (isset(self::$classMap[$class]))
{
return require __DIR__ . self::$classMap[$class];
}
$file = __DIR__ . '/classes/' . str_replace('\\', '/', $class) . '.php';
if (is_file($file) === FALSE)
{
return FALSE;
}
return require $file;
}, true, true);
}
protected static $classMap = array(
'IP' => '/vendor/IP.class.php'
);
}
class App extends Application
{
}
App::run();