-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
71 lines (48 loc) · 1.5 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
<?php
header('Content-Type: text/html; charset=utf-8');
ini_set('display_errors', 'On');
error_reporting(E_ALL);
session_start();
define('BASE_DIR', __DIR__);
include_once '/config/defaults.php';
include_once '/sys/autoloader.php';
include_once '/sys/shortcuts.php';
$url_path = $_SERVER['REQUEST_URI'];
$url_parts = explode('?', $url_path);
$url_path = always_set($url_parts, 0, '');
$url_path = trim(trim($url_path), '/');
$url_query = always_set($url_parts, 1, '');
$url_query_array = array();
parse_str($url_query, $url_query_array);
$url_array = array();
if ($url_path)
{
$url_array = explode('/', $url_path);
}
$controller_name = always_set($url_array, 0, $defaults_config['location']['controller']);
$action_name = always_set($url_array, 1, $defaults_config['location']['action']);
$action_name = str_replace('-', '', $action_name);
array_shift($url_array);
array_shift($url_array);
$other_params = $url_array;
$_GET = array_merge($_GET, $url_query_array);
$_GET['controller'] = strtolower($controller_name);
$_GET['action'] = strtolower($action_name);
if (!file_exists(BASE_DIR.'/controllers/'.$controller_name.'.php'))
{
include_once '/sys/404.php';
return ;
}
$controller_class = 'Controllers_'.ucfirst($controller_name);
if (!class_exists($controller_class))
{
include_once '/sys/404.php';
return ;
}
$controller_object = new $controller_class();
if (!method_exists($controller_object, $action_name))
{
include_once '/sys/404.php';
return ;
}
$controller_object->{$action_name}($other_params);