public function getController($url) { $routing_file = file_get_contents(self::FILE_ROUTE); $routing = json_decode($routing_file); if (!isset($routing->{UriAnalyzer::getController($url)})) { throw new \Exception(self::MESSAGE); } return $routing->{UriAnalyzer::getController($url)}; }
public function execute() { $routing = new Routing(); try { $cache = new MemoryCache(); $route = $routing->getController($this->request->getUri()); $controller_name = $route->{"controller"}; $action = $route->{"action"}; $controller = new $controller_name(); $cache_params = $controller->getCacheDefinition(UriAnalyzer::getParameters($this->request->getUri()), $action); $content = $cache->get($cache_params); if (!$content) { $response = $controller->build($this->request, $action); $cache->set($cache_params, $response->getContent(), 1); return $response; } else { $response = new ResponseHttp($content); return $response; } } catch (\Exception $e) { echo $e->getMessage(); } }