-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
66 lines (54 loc) · 1.35 KB
/
bootstrap.php
File metadata and controls
66 lines (54 loc) · 1.35 KB
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
<?php
/**
* Begin session
*/
session_start();
/**
* Error reporting switch
*/
switch ($_SERVER['REMOTE_ADDR']) {
case '127.0.0.1':
error_reporting(E_ALL);
break;
default:
error_reporting(-1);
break;
}
/**
* Register autoloader with the SPL
*/
spl_autoload_register(function ($class) {
$class = str_replace('\\', DIRECTORY_SEPARATOR, $class);
$class_path = __DIR__ . DIRECTORY_SEPARATOR . 'src'. DIRECTORY_SEPARATOR . $class . '.php';
if (file_exists($class_path) === false) {
throw new Exception('Failed to autoload class "' . $class . '"', 500);
}
return require_once $class_path;
});
/**
* Routing switch
*/
switch ($_SERVER['REQUEST_URI']){
case '/home':
case '/index.php':
header('Location: /', true, 301);
break;
case '/':
$template = new Template('pages/home.html');
echo $template->get();
break;
default:
try {
$template = new Template('pages/' . $_SERVER['REQUEST_URI'] . '.html');
echo $template->get();
} catch (\Exception\NotFoundException $e) {
header('Content-type: text/html', true, 404);
$template = new Template('errors/404.html');
echo $template->get();
}
break;
}
/*
* Close any open mysqli connections
*/
\Mysqli\DB::close();