-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
32 lines (25 loc) · 1.28 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
<?php
use TPetersen\MVCTemplate\Config;
try {
require_once('config/constants.php');
require_once('sys/sys.php');
$parameters = array_merge($_GET, $_POST);
$controllerName = isset($parameters['controller']) ? $parameters['controller'] : Config::getConfigByKey('CONTROLLER', 'DEFAULT');
$actionName = isset($parameters['action']) ? $parameters['action'] : Config::getConfigByKey('ACTION', 'DEFAULT');
$controllerClass = Config::getConfigByKey('CONTROLLER', 'NAMESPACE') . ucfirst($controllerName) . 'Controller';
$actionMethod = $actionName . 'Action';
$controllerReflection = new ReflectionClass($controllerClass);
if (!$controllerReflection->isSubclassOf(Config::getConfigByKey('CONTROLLER', 'NAMESPACE') . 'AbstractBaseController')) {
throw new Exception($controllerClass . ' is not a valid Controller', 1395840233);
}
if (!$controllerReflection->hasMethod($actionMethod)) {
throw new Exception('Action ' . $actionMethod . ' not found in Class ' . $controllerClass, 1395840234);
}
$controller = new $controllerClass();
$controller->$actionMethod();
} catch (Exception $e) {
ob_end_clean();
echo 'Oops an Error occured! <br>';
echo '<strong>Error Message: </strong>' . $e->getMessage() . '<br>
<strong>Error Code: </strong>' . $e->getCode() . '<br>';
}