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 string $url * @return \MicroMuffin\Router\Route|null */ public static function get($url) { $url_chunks = self::getUrlChunks($url); foreach (self::$routes as $route) { $route_chunks = self::getUrlChunks($route->getUrl()); $diff = count($route_chunks) - count($url_chunks); if ($diff <= $route->getOptionalParameters() && $diff >= 0) { $match = true; $parameters = array(); for ($i = 0; $match && $i < count($url_chunks) && $i < count($route_chunks); $i++) { $url_chunk = $url_chunks[$i]; $route_chunk = $route_chunks[$i]; if (self::isParameter($route_chunk, self::SYMBOL_MANDATORY)) { if (preg_match(self::PARAM_MANDATORY_REGEXP, $url_chunk)) { $parameter_name = ltrim($route_chunk, self::SYMBOL_MANDATORY); $parameters[$parameter_name] = $url_chunk; } else { $match = false; } } else { if (self::isParameter($route_chunk, self::SYMBOL_OPTIONAL)) { if (preg_match(self::PARAM_OPTIONAL_REGEXP, $url_chunk)) { $parameter_name = ltrim($route_chunk, self::SYMBOL_OPTIONAL); $parameters[$parameter_name] = $url_chunk; } else { $match = !empty($url_chunk); } } else { if ($url_chunk != $route_chunk) { $match = false; } } } } if ($match) { foreach ($route->getFilters() as $filter) { foreach (self::$filters as $filter_ref) { if ($filter_ref->name == $filter) { $result = $filter_ref->exec(); if ($result != null) { if ($filter_ref->name == "login") { Controller::setIntented("/" . $url); } Controller::redirect($result); } } } } $extRoute = clone $route; $extRoute->setParameters($parameters); return $extRoute; } } } return null; }