public static function putHeader($header, $replace = true, $code = null) { if (self::$dispatchedHeaders) { if (is_numeric($code)) { header($header, $replace, $code); self::$httpCode = $code; App::on('changestatus', array($code, null)); } else { header($header, $replace); } return null; } if (is_string($header) && is_bool($replace) && ($code === null || is_numeric($code))) { self::$headers[] = array($header, $replace, $code); return count(self::$headers); } return false; }
public function __construct($expires = 900, $lastModified = 0, $prefix = '') { $this->expires = $expires; if (AppData::createFolder('cache/output') === false) { return null; } $this->lastModified = $lastModified === 0 ? REQUEST_TIME + $this->expires : $lastModified; $filename = INPHINIT_PATH . 'storage/cache/output/~'; if (false === empty($prefix)) { $filename .= strlen($prefix) . '.' . sha1($prefix) . '_'; } $path = \UtilsPath(); $filename .= sha1($path) . '-' . strlen($path); $lastModify = $filename . '.1'; $this->cacheName = $filename; if (file_exists($filename) && file_exists($lastModify)) { $data = file_get_contents($lastModify); if ($data !== false && $data > REQUEST_TIME) { $this->isCache = true; header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $data) . ' GMT'); header('Etag: ' . sha1_file($filename)); if (self::match($data)) { Response::status(304); } else { App::on('ready', array($this, 'show')); } return null; } } $this->cacheTmp = AppData::createTmp(); $tmp = fopen($this->cacheTmp, 'wb'); if ($tmp === false) { return null; } $this->handle = $tmp; App::on('ready', array($this, 'finish')); App::buffer(array($this, 'write'), 1024); }