public function __construct(Router $_router, $_ = array()) { $this->lang = $_router->getLang(); if (!in_array($this->lang, \Ker\Config::getOne("allowedLanguages"))) { $this->lang = \Ker\Config::getOne("defaultLanguage"); $this->setError(404); return; } $this->module = $_router->getModule(); $this->action = $_router->getAction(); $this->data = $_router->getData(); $this->extra = $_router->getExtra(); $view = $this->getView(); if (!$this->module) { $this->module = "Index"; $this->action = "index"; } elseif (isset($_["requireViewFile"]) and $_["requireViewFile"] and !file_exists($view::getViewFile($this->lang, $this->module, $this->action))) { $this->setError(404); } }
/** * Output API result * * @param bool $success Is success flag * @param Router $router Current instance of Router * @param string|array $data Output data */ function setResult($success, Router $router, $data = "") { header("Content-Type: application/json"); echo json_encode(array("module" => $router->getModule(), "method" => $router->getMethod(), "success" => (bool) $success, "data" => $data)); }
/** * Run the application. * * @api */ public function dispatch() { # get current context from URL try { Router::resolve(isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/'); Router::updateHtaccess(); #Router::updateRules(); } catch (\Exception $e) { Session::addErrorMsg($e->getMessage()); } // from here we'll capture every output ob_start(); // we need the session this early, (feel free to remove the following line and get stuck with session problems) Session::getInstance(); $module = Router::getModule(); $action = Router::getAction(); $view = $this->handleRequest($module, $action); // threat all unwanted output as error output $errors = ob_get_clean(); if (trim($errors) !== '') { Session::addErrorMsg($errors); } // finally deliver page $view->display(); }