context = $context; if (isset($makeRequest)) { $this->makeRequest = $makeRequest; } else { $makeRequestClass = Config::get('makerequest_class'); $this->makeRequest = new $makeRequestClass(); } } /** * Sets the caching (Cache-Control & Expires) with a cache age of $lastModified * or if $lastModified === false, sets Pragma: no-cache & Cache-Control: no-cache * * @param boolean $lastModified */ protected function setCachingHeaders($lastModified = false) { $maxAge = $this->context->getIgnoreCache() ? false : $this->context->getRefreshInterval(); if ($maxAge) { if ($lastModified) { header("Last-Modified: $lastModified"); } // time() is a kernel call, so lets avoid it and use the request time instead $time = $_SERVER['REQUEST_TIME']; $expires = $maxAge !== false ? $time + $maxAge : $time - 3000; $public = $maxAge ? 'public' : 'private'; $maxAge = $maxAge === false ? '0' : $maxAge; header("Cache-Control: {$public}; max-age={$maxAge}", true); header("Expires: " . gmdate("D, d M Y H:i:s", $expires) . " GMT", true); } else { header("Cache-Control: no-cache", true); header("Pragma: no-cache", true); } } /** * Returns the request headers, using the apache_request_headers function if it's * available, and otherwise tries to guess them from the $_SERVER superglobal * * @return array */ protected function request_headers() { // Try to use apache's request headers if available if (function_exists("apache_request_headers")) { if (($headers = apache_request_headers())) { return $headers; } } // if that failed, try to create them from the _SERVER superglobal $headers = array(); foreach (array_keys($_SERVER) as $skey) { if (substr($skey, 0, 5) == "HTTP_") { $headername = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($skey, 0, 5))))); $headers[$headername] = $_SERVER[$skey]; } } return $headers; } }