-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
81 lines (68 loc) · 2.26 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
<?php
session_start();
// Require all PHP files from a directory
$folderList = [
'./config/',
'./app/Core/',
'./lib/',
];
$gfgFolderList = ['Controller' => './app/Controller/'];
foreach ($folderList as $folder) {
foreach (glob($folder . "*.php") as $filename) {
if (file_exists($filename)) {
require $filename;
}
}
}
require './app/Model/BaseModel.php';
require './app/Controller/Controller.php';
if (is_dir($gfgFolderList['Controller'])) {
if ($gfgDir = opendir($gfgFolderList['Controller'])) {
// Loop through the directory
while (($gfgSubFolder = readdir($gfgDir)) !== false) {
$gfgTempPath = $gfgFolderList['Controller'] . $gfgSubFolder . '/';
if (is_dir($gfgTempPath) && $gfgSubFolder != '.'
&& $gfgSubFolder != '..'
) {
$gfgFolderList[$gfgSubFolder] = $gfgTempPath;
}
}
closedir($gfgDir);
}
}
// ------------------------------------------------------------------------
// Get Controller
if (isset($_REQUEST['controller']) && '' != $_REQUEST['controller']) {
$controllerParam = strtolower($_REQUEST['controller']);
}
$controllerNamePrefix = ucfirst($controllerParam ?? '');
$controllerName = $controllerNamePrefix . 'Controller';
foreach ($gfgFolderList as $folder) {
$fileTemp = $folder . $controllerName . '.php';
if (class_exists($controllerName)) {
break;
} elseif (file_exists($fileTemp)) {
require $fileTemp;
}
}
// ------------------------------------------------------------------------
// Get Action
if (isset($_REQUEST['action']) && '' != $_REQUEST['action']) {
$actionParam = strtolower($_REQUEST['action']);
}
$actionName = $actionParam ?? 'Index';
// ------------------------------------------------------------------------
// 404 page for not found controller
if (!class_exists($controllerName)) {
$controllerName = 'Controller';
$actionName = 'NotFound';
}
// ------------------------------------------------------------------------
//Run
$controllerObject = new $controllerName();
if (method_exists($controllerObject, $actionName)) {
$controllerObject->$actionName();
} else {
$controllerObject = new Controller();
$controllerObject->notFound();
}