-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathendpoint.php
More file actions
55 lines (45 loc) · 1.37 KB
/
endpoint.php
File metadata and controls
55 lines (45 loc) · 1.37 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
<?php
require __DIR__ . '/vendor/autoload.php';
use JVVM\Frontend\Content;
use JVVM\Frontend\Router;
use JVVM\Backend\PDO;
use JVVM\Backend\Session;
use JVVM\Frontend\Response;
use JVVM\Utils\Exceptions\MalformedRoute;
use JVVM\Utils\URI;
use JVVM\Utils\HTTPMethod;
use JVVM\Utils\RouterMethod;
ob_start();
try {
$pdo = new PDO('mysql:host=localhost;dbname=jvvm', 'jvvm', 'jvvm');
$response = new Response();
$router = new Router();
$router->set_filter('uid', [Content\Member::class, 'id_filter']);
$session = new Session();
$registering_function = 'register_limited';
if ($session->has_session()) {
$registering_function = 'register';
}
$router->add(
RouterMethod::redirect(),
new URI('user/{*}'),
fn() => new URI('member')
);
$uri = URI::fromRequest($_SERVER['REQUEST_URI']);
/* Register only a subset of route */
$class = '';
error_log($uri->get_base());
switch($uri->get_base()) {
case Content\Member::get_base(): $class = Content\Member::class; break;
case Content\Register::get_base(): $class = Content\Register::class; break;
}
if (!empty($class)) {
call_user_func([$class, $registering_function], $router, $response);
}
$router->run($uri);
} catch (Exception $e) {
error_log($e->getMessage());
http_response_code(500);
}
ob_end_flush();
exit(0);