-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
42 lines (30 loc) · 772 Bytes
/
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
<pre><?php
function autoloader($className)
{
$path = str_replace('_', '/' ,$className).".php";
require_once('app/'.$path);
}
if ( ! spl_autoload_register( 'autoloader' ) ) {
throw new Exception('Autoloader failed');
}
// include configs
foreach( glob('config/*.php') as $fn ) {
include $fn;
}
// find route, if it exists
$found = false;
$Uri = $_SERVER['REQUEST_URI'];
foreach ( array_keys( $routes ) as $routeRegex ) {
if ( preg_match( $routeRegex, $Uri ) ) {
$found = true;
$controller = $routes[ $routeRegex ]['controller'];
$method = $routes[ $routeRegex ]['method'];
$theController = new $controller;
$theController->$method();
break;
}
}
if ( ! $found ) {
echo "No route";
}
?>