public function __construct() { $this->benchmark =& getBenchmarkInstance(); $this->output =& getOutputInstance(); $this->benchmark->mark("controller_construct"); $this->db = new Db(); }
public function init() { $benchmark =& getBenchmarkInstance(); $benchmark->mark("application_start"); $output =& getOutputInstance(); $url = isset($_GET['url']) ? $_GET['url'] : ''; $this->getRouter()->setUrl($url); $controller = $this->getRouter()->getController(); $action = $this->getRouter()->getAction(); $parameters = $this->getRouter()->getParameters(); // Verifico que este autorizado if (is_null($this->getSecurity()) || $this->getSecurity()->isAuthorized($controller, $action, $parameters)) { // Verifico cache if ($this->getCache()->exists($controller, $action, $parameters)) { $time = $this->getCache()->getExpiration($controller, $action, $parameters); $fileName = $this->getCache()->getFilename($controller, $action, $parameters); if ($output->displayFromCache($fileName, $time)) { // Imprimo desde cache y salgo exit; } } $benchmark->mark("controller_start c:{$controller} a:{$action}"); $this->getRouter()->dispatch(); $benchmark->mark("controller_end"); $benchmark->mark("controller_end"); $benchmark->mark("application_end"); if ($output->hasContent()) { $output->display(); } } else { $url = $this->getSecurity()->getAccessDeniedUrl(); if (!is_null($url)) { header('Location: ' . $url); } else { header("HTTP/1.1 401 Unauthorized"); } exit; } }
public function displayFromCache($archivo, $tiempo) { $benchmark =& getBenchmarkInstance(); $benchmark->mark("displayFromCache_start"); $retorno = false; $this->archivo = $archivo; if ($html = $this->get($archivo, $tiempo)) { if (!headers_sent()) { header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); header('Content-Type: text/html; charset=utf-8'); } $benchmark->mark("displayFromCache_end"); echo str_replace("%BENCHMARK%", $benchmark->getTimestampsAsHtmlComment(), $html); $retorno = true; } else { $benchmark->mark("cache old"); $this->escribirCache = true; } $benchmark->mark("displayFromCache_end"); return $retorno; }