-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.php
40 lines (30 loc) · 952 Bytes
/
run.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
<?php
require_once('./init.php');
// Initialize Request
$router = new Router();
try{
// Parse the request and retrieve controller
$controller_name = $router->parse($_SERVER);
}catch(Exception $err){
// Initialize printing machine
$output = new Printer('json');
$output->error('System', $err);
exit();
}
// Initialize printing machine
$output = new Printer($router->format);
try{
// Define the correct action from controller
$controller = new $controller_name($db_mode, $db_config);
$action_name = strtolower($router->verb) . 'Action';
// Execute the action
$result = $controller->$action_name($router);
// Set template if needed
if(!empty($router->view) && $router->format === 'html') $output->setTemplate($router->view);
// Render result
$output->success($router->type, $result);
}catch(Exception $err){
// Output error
$output->error($router->type, $err);
}
?>