-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·87 lines (62 loc) · 2.32 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
78
79
80
81
82
83
84
85
86
87
<?php
require "vendor/autoload.php";
use Klein\Klein;
use OneT\Accounts;
use OneT\Api;
use OneT\Database;
use OneTUI\Views;
$config = parse_ini_file("config.ini");
$klein = new Klein();
$klein->respond(function ($request, $response, $service, $app) use ($config, $klein) {
// Handle exceptions => flash the message and redirect to the referrer
$klein->onError(function ($klein, $err_msg) {
$klein->service()->flash($err_msg);
$klein->service()->flashes();
echo $err_msg;
// $klein->service()->back();
});
// lazy services (Only get instantiated on first call)
$app->register('pdo', function () use ($config) {
// Replace the values in config.ini with your actual database login details
return Database::newConnection($config);
});
$app->register('api', function () use ($app) {
return new Api($app->pdo);
});
$app->register('accounts', function () use ($app) {
return new Accounts($app->pdo);
});
$app->register('views', function () use ($request, $app, $service) {
$views = new Views($app, $service);
return $views->setSiteUrl($app->api->getSiteUrl($request));
});
});
$pages = [
'user',
'links',
'debug'
];
$view = function ($request, $response, $service, $app) use ($klein) {
$app->views->show($request, $response, $service, $app);
};
$protectedView = function ($request, $response, $service, $app) use ($klein) {
$app->views->showProtected($request, $response, $service, $app);
};
$klein->respond('GET', '/', $view);
$klein->respond('GET', '/[user|links:page]', $protectedView);
$klein->respond(['POST', 'GET'], '/api/[a:action]', function ($req, $resp, $service, $app) {
$app->api->execute($req, $resp);
});
$klein->respond(['POST', 'GET'], '/[a:link_hash_id]', function ($req, $resp, $service, $app) use ($pages, $klein) {
if (!in_array($req->link_hash_id, $pages)) {
$app->api->resolve($req, $resp);
}
});
$klein->respond(['POST', 'GET'], '/accounts/[a:action]', function ($req, $resp, $service, $app) {
$app->accounts->execute($req, $resp);
});
$klein->respond('GET', '/debug', function ($req, $resp, $service, $app) {
session_start();
var_dump($_SESSION);
});
$klein->dispatch();