forked from macno/fluidframe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
68 lines (54 loc) · 1.73 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
<?php
define('FLUIDFRAME',true);
define('INSTALLDIR', dirname(__FILE__));
require_once(INSTALLDIR.'/lib/core.php');
try {
Fluidframe::init();
$_lang = common_language();
} catch(Exception $e) {
common_error($e->getTraceAsString());
$error = new ErrorAction('en');
$error->setErrorMessage(500, $e->getMessage());
$error->handle();
}
// get the incoming request URL path
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
// get the route based on the path and server
$route = $router->match($path, $_SERVER);
if(empty($route)) {
$error = new ErrorAction($_lang);
$error->setErrorMessage(404, 'Unkown page');
$error->handle();
}
// does the route indicate an action?
if (isset($route->params['action'])) {
// take the action class directly from the route
$action = $route->params['action'];
} else {
// use a default action class
$action = 'home';
}
$action_class = ucfirst($action).'Action';
if (!class_exists($action_class)) {
$error = new ErrorAction($_lang);
$error->setErrorMessage(400, 'Unkown action <'.$action_class.'>');
$error->handle();
}
$actionClass = new $action_class($_lang);
try {
if($actionClass->prepare($route->params)) {
$actionClass->handle();
}
} catch(ClientException $e) {
$error = new ErrorAction($_lang);
$error->setErrorMessage($e->getCode(), 'ClientException:' . $e->getMessage());
$error->handle();
} catch(ServerException $e) {
$error = new ErrorAction($_lang);
$error->setErrorMessage($e->getCode(), 'ServerException: '.$e->getMessage());
$error->handle();
} catch(Exception $e) {
$error = new ErrorAction($_lang);
$error->setErrorMessage(500, 'Exception: '. $e->getMessage());
$error->handle();
}