-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
77 lines (61 loc) · 1.79 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
<?php
header("Content-Type: text/html");
include __DIR__ . '/vendor/autoload.php';
use WCal\Controller\TemplateManager;
use WCal\Controller\DataWorker;
/* Constant that enables debuging tools Whoops and Kint */
define("DEBUG", true);
/* Check if debug is eanbled */
if (DEBUG){
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();
Kint::$theme = 'solarized-dark';
} else {
Kint::enabled(false);
}
$router = new AltoRouter();
$router->setBasePath('');
// Setup the URL routing.
// 1-http request, 2-matching url, 3-path to match, 4-name
$router->map('GET','/', function(){
$tmanager = new TemplateManager();
$tmanager->home();
}, 'home');
$router->map('GET', '/form/', function(){
$tmanager = new TemplateManager();
$tmanager->form();
}, 'form');
$router->map('GET', '/data/', function(){
$tmanager = new TemplateManager();
$tmanager->data();
}, 'about');
$router->map('GET', '/about/', function(){
$tmanager = new TemplateManager();
$tmanager->about();
});
$router->map('POST','/write/', function(){
$worker = new DataWorker();
$worker->saveData();
});
$router->map('GET', '/delete/[i:id]/' , function($id){
$worker = new DataWorker();
$worker->deleteData($id);
});
$router->map('GET', '/update/[i:id]/' , function($id){
$tmanager = new TemplateManager();
$tmanager->update($id);
});
$router->map('POST', '/update/' , function(){
$worker = new DataWorker();
$worker->update();
});
$match = $router->match();
# If a matching route is found
if( $match && is_callable( $match['target'] ) ) {
call_user_func_array( $match['target'], $match['params']);
} else {
// no route was matched show 404 page
header("HTTP/1.0 404 Not Found");
require 'static/404.html';
}