private function execute() { if (method_exists($this->controller, 'before_filter')) { $this->controller->before_filter($this->route->getParameters()); } $action = $this->action; $this->controller->{$action}($this->route->getParameters()); //View displaying $render = $this->controller->getRender(); if ($render != "false") { Internationalization::init(); $twig_options = array('cache' => false, 'autoescape' => false, 'strict_variables' => true); $loader = new \Twig_Loader_Filesystem('../' . VIEW_DIR . strtolower($this->route->getController())); $twig = new \Twig_Environment($loader, $twig_options); $twig->addFilter("tr", new \Twig_Filter_Function("\\MicroMuffin\\Internationalization::translate")); $twig->addFilter("url", new \Twig_Filter_Function("\\MicroMuffin\\Tools::sanitizeForUrl")); $page = $twig->render(($render == "true" ? $this->action : $render) . ".html.twig", $this->controller->getVariables()); //Base layout execution and displaying $layout = $this->controller->getRenderLayout(); if ($layout != "false") { $loader = new \Twig_Loader_Filesystem('../' . VIEW_DIR . 'base'); $twig = new \Twig_Environment($loader, $twig_options); $twig->addFilter("tr", new \Twig_Filter_Function("\\MicroMuffin\\Internationalization::translate")); $twig->addFilter("url", new \Twig_Filter_Function("\\MicroMuffin\\Tools::sanitizeForUrl")); $base = new \BaseController(); $base->{$layout}(); $params = $base->getVariables(); $params = array_merge($params, $this->controller->getLayoutVariables()); $params['_page'] = $page; echo $twig->render($layout . ".html.twig", $params); } else { echo $page; } } }
/** * @param array $content * @throws \Exception */ public static function add(array $content) { if (!array_key_exists("url", $content) || !array_key_exists("controller", $content) || !array_key_exists("action", $content)) { throw new \Exception("Invalid route. Either URL, controller or action is messing."); } else { $filters = array(); if (array_key_exists("filters", $content)) { $filters = explode(",", $content['filters']); } $route = new Route(); $route->setAction($content['action']); $route->setController($content['controller']); $route->setUrl($content['url']); $route->setFilters($filters); $route->setOptionalParameters(substr_count($content['url'], '@')); self::$routes[] = $route; } }