-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
56 lines (43 loc) · 1.57 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
<?php
/*
echo hash('sha512', 'jazavac6086hgodfhgouhy98ugodfgod6');
exit;
*/
ob_start();
require_once 'sys/Autoload.php';
Session::begin();
$uriWithBase = filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_STRING);
$uri = substr($uriWithBase, strlen(Configuration::BASE_PATH));
$Routes = require_once 'Routes.php';
$FoundRoute = null;
$Arguments = [];
foreach ($Routes as $Route) {
if (preg_match($Route['Pattern'], $uri, $Arguments)) {
$FoundRoute = $Route;
break;
}
}
unset($Arguments[0]);
$Controller = $FoundRoute['Controller'];
$Method = $FoundRoute['Method'];
$fileName = 'app/controllers/' . $Controller . 'Controller.php';
if (!file_exists($fileName)) {
$Controller = 'Main';
$fileName = 'app/controllers/' . $Controller . 'Controller.php';
}
require_once $fileName;
$className = $Controller . 'Controller';
$worker = new $className;
$Method = method_exists($worker, $Method)?$Method:'index';
call_user_func_array([$worker, '__pre'], []);
call_user_func_array([$worker, $Method], $Arguments);
// Data from the controller response
$DATA = $worker->getData();
if ($worker instanceof ApiController) {
ob_clean();
header('Content-type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin');
echo json_encode($DATA, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
}
require_once 'app/views/'.$Controller.'/'.$Method.'.php';