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); } }
//$app->add(new \CheckMiddleware()); // ------------------------------------------------o Register Twig //$app->view->parserExtensions = array(new \Slim\Views\TwigExtension()); // ------------------------------------------------o Cache instanciation + Clear cache —> Standing by for now /*$jsonCache = new JSONCache; $app->get('/', function() use ($app, $jsonCache){ $forceCache = $app->request()->params('forceCache'); if ($forceCache == true){ $jsonCache->clear(); echo "Cache cleared"; } });*/ // ------------------------------------------------o App request $app->get('(/)(/:params+)', function ($params = array()) use($app, $router) { $data = $router->getData($params); $data['ajax'] = $app->request->isAjax(); if (!isset($data['route']->view)) { $statusCode = 404; if ($data['ajax'] == true) { $statusCode = 200; } $data['route'] = array('view' => '404'); $app->render($data['viewFolder'] . 'pages/404.html.twig', $data, $statusCode); } else { /*if ($data['ajax'] == false){ $jsonCache->generate($data['lang']); }*/ $app->render($data['viewFolder'] . '/pages/' . $data['route']->view . '.html.twig', $data); } });