-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
98 lines (79 loc) · 2.27 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
<?php
date_default_timezone_set( "Asia/Tokyo" );
require_once( $_SERVER['DOCUMENT_ROOT']."/config.php" );
require __DIR__ . '/vendor/autoload.php';
use Config\Config;
$config = new Config;
foreach( glob($config->dir_root."/inc/*php" ) as $filename ){
include $filename;
}
foreach( glob( $config->dir_root."/app/*.php" ) as $filename ){
require_once($filename);
}
use Includes\Parser\URI as uriparser;
$uriArray = uriparser::parseUri( trim($_SERVER['REQUEST_URI'],"/") );
require_once( $config->controller."base.php" );
require_once( $config->model."base.php" );
if( isset($_GET['class']) && $_GET['class'] !='' ){
try{
if( file_exists( $config->controller.trim($_GET['class']).".php" ) ){
require_once( $config->controller.trim($_GET['class']).".php" );
$control = "Controller\\".trim( $_GET['class'] );
$controller = new $control;
$function = "index";
if( isset( $_GET['function'] ) && $_GET['function'] != ""){
$function = trim( $_GET['function'] );
}
$vars = array();
$uri_size = sizeof($uriArray);
foreach($uriArray as $k => $v){
foreach($_GET as $key => $var){
if($key == 'class' && $v != $var){
$vars[] = $v;
}
}
}
if(isset($vars[0]) && $vars[0] == "f"){
$function = trim($vars[1]);
unset($vars[0]);
unset($vars[1]);
$vars = array_values($vars);
}
try{
if(is_callable(array("Controller\\".trim($_GET['class']),$function))) {
call_user_func_array(array($controller,$function),array($vars));
} else {
new Includes\Error\MissingFunction;
}
} catch(Exception $e){
echo $e;
}
} else{
new Includes\Error\MissingController;
}
} catch(Exception $e){
echo $e;
}
} else if( isset($_GET['class']) && $_GET['class'] =='' ){
try{
if( file_exists( $config->controller.$config->default.".php" ) ){
require_once( $config->controller.$config->default.".php" );
$control = "Controller\\".$config->default;
$controller = new $control;
$vars = array();
foreach($uriArray as $k => $v){
foreach($_GET as $key => $var){
if($v != $var){
$vars[] = $v;
}
}
}
call_user_func_array( array( $controller,"index" ), array( $vars ) );
} else{
new Includes\Error\MissingController;
}
} catch(Exception $e){
echo $e;
}
}
?>