/** * makes all routes */ static function start() { $routes = explode('/', $_SERVER['REQUEST_URI']); if (!Authorize::checkAuth() && ($routes[1] != 'register' || $routes[1] == 'langchange')) { // pre-check authorisation if ($routes[1] == 'langchange') { include Module::CONTROLLER_PATH . 'ControllerMain.php'; $controller = new ControllerMain(); $controller->actionlangchange(); } else { include Module::CONTROLLER_PATH . 'ControllerAuth.php'; $controller = new ControllerAuth(); $controller->actionlogin(); } } else { $routeNames = Module::getRoutes(); $controllerName = 'Main'; $actionName = 'index'; // generate controller name if (!empty($routes[1])) { if (isset($routeNames[$routes[1]])) { $controllerName = $routeNames[$routes[1]]['controller']; // get action if (!empty($routes[2])) { $actionName = $routes[2]; } else { $actionName = $routeNames[$routes[1]]['action']; } } else { Route::ErrorPage404(); } } // need for get names with prefixes $modelName = 'Model' . $controllerName; $controllerName = 'Controller' . $controllerName; $actionName = 'action' . ucfirst($actionName); $modelFile = $modelName . Module::DEFAULT_EXT; $modelPath = Module::MODEL_PATH . $modelFile; if (file_exists($modelPath)) { include $modelPath; } $controllerFile = $controllerName . Module::DEFAULT_EXT; $controllerPath = Module::CONTROLLER_PATH . $controllerFile; if (file_exists($controllerPath)) { include $controllerPath; } else { Route::ErrorPage404(); } $controller = new $controllerName(); $action = $actionName; if (method_exists($controller, $action)) { $controller->{$action}(); } else { Route::ErrorPage404(); } } }