function run($class, $method) { $controllerName = App::getConfig()['controllerNamespace'] . "\\" . $class . "Controller"; $actionMethodName = $method . "Action"; if (class_exists($controllerName)) { $controller = new $controllerName(); if (!$controller instanceof Controller) { throw new ApplicationException("Class {$controller} does not extends Controller"); } $viewName = App::getConfig()["viewsNamespace"] . "\\" . $class . "View"; if (class_exists($viewName)) { $view = new $viewName(); if (!$view instanceof View) { throw new ApplicationException("Class {$view} does not implements IView"); } $controller->setView($view); if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { if (method_exists($view, $actionMethodName)) { $view->{$actionMethodName}(); } else { throw new ApplicationException("Method {$actionMethodName} does not exists."); } } else { if (method_exists($controller, $actionMethodName)) { $controller->{$actionMethodName}(); } else { throw new ApplicationException("Method {$actionMethodName} does not exists."); } } } else { throw new ApplicationException("Class {$controllerName} does not exists."); } } else { throw new ApplicationException("Class {$controllerName} does not exists."); } }
function createDatabase() { $db = new \PDO(App::getConfig()["dsn"], App::getConfig()["dbUser"], App::getConfig()["dbPass"]); $db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); return $db; }