-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
executable file
·64 lines (45 loc) · 1.56 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
<?php
use Framework\Helper\ViewHelperContainer;
use Framework\Http\RequestImp;
use Framework\Router;
use Framework\Routing\RoutesBuilder;
try {
loadClasses();
$wrapper = include "config/routing.php";
$routes = loadRoutes($wrapper);
$roleChecker = new \Framework\RoleChecker();
ViewHelperContainer::append([
'role_checker' => new \Framework\Helper\RoleCheckHelper($roleChecker),
'route_path' => new \Framework\Helper\RoutePathHelper($routes)
]);
$controllerInvoker = new \Framework\Controller\ControllerInvoker();
$controllerInvoker->setRoleChecker($roleChecker);
$router = new Router($routes, $controllerInvoker);
$request = RequestImp::createFromGlobals();
$router->handle($request);
} catch (Exception $ex) {
echo $ex->getMessage();
}
function loadRoutes($wrapperClosure) {
$routeBuilder = new RoutesBuilder();
$wrapperClosure($routeBuilder);
return $routeBuilder->build();
}
function loadClasses() {
// Specific app loader
if(file_exists("config/autoloader.php")) {
$loader = include "config/autoloader.php";
spl_autoload_register($loader);
}
// Framework loader
spl_autoload_register(function($class) {
$path = str_replace('\\', '/', $class);
$segments = explode('/', $path);
for($i = 0; $i < count($segments) - 1; $i++) {
$segments[$i] = strtolower($segments[$i]);
}
$path = implode('/', $segments);
include $path . '.php';
});
}
?>