/** * Save a cached file of the output * * @param $content */ protected function writeCacheFile($content) { $dir = $this->temp_dir . DIRECTORY_SEPARATOR . 'synergy'; Logger::debug('Synergy cache dir: ' . $dir); if (!is_dir($dir)) { Tools::mkdir($dir); } $file = $dir . DIRECTORY_SEPARATOR . md5($this->request->getUri()) . '.syn'; $fh = fopen($file, 'w'); fputs($fh, $content, strlen($content)); @fclose($fh); if (!$this->isDev && $this->useGzip()) { Logger::info('Compressing response'); $zp = gzopen($file . '.gz', 'w9'); gzwrite($zp, $content); gzclose($zp); // remove gzip file if it's bigger than the unzipped file if (filesize($file . '.gz') > filesize($file)) { unlink($file . '.gz'); } } }
/** * Prepares the cache folder for Smarty * * @return void */ private function initSmartyCache() { if (!is_dir($this->cacheDir)) { Tools::mkdir($this->cacheDir, true); } // compiled templates dir $path = $this->cacheDir . DIRECTORY_SEPARATOR . 'templates_c' . DIRECTORY_SEPARATOR; if (!is_dir($path)) { Tools::mkdir($path, false); } $this->loader->setCompileDir($path); // cache dir $path = $this->cacheDir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR; if (!is_dir($path)) { Tools::mkdir($path, false); } $this->loader->setCacheDir($path); // configs dir $path = $this->cacheDir . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR; if (!is_dir($path)) { Tools::mkdir($path, false); } $this->loader->setConfigDir($path); }
/** * @param $filename * * @throws InvalidArgumentException */ public function setFilename($filename) { // close any open file resource before changing the filename $this->closeFH(); $filename = trim($filename); // check the filename is valid before setting if (is_string($filename) && substr($filename, 0, 1) == DIRECTORY_SEPARATOR) { // split out the parts of the filename $parts = pathinfo($filename); // clean the filename $filename = $parts['dirname'] . DIRECTORY_SEPARATOR . preg_replace("/[^A-Za-z0-9+]/", '_', $parts['filename']); if (isset($parts['extension']) && strlen($parts['extension']) > 0) { $filename .= '.' . $parts['extension']; } // test the dir if (!is_dir($parts['dirname']) && !is_writable(dirname($parts['dirname']))) { throw new InvalidArgumentException("filename must be an absolute filename in a writeable directory : {$filename}"); } else { if (!Tools::mkdir($parts['dirname'], true)) { throw new InvalidArgumentException("filename must be an absolute filename in a writeable directory : {$filename}"); } } // Test an existing file is writable if (file_exists($filename) && !is_writable($filename)) { $processUser = posix_getpwuid(posix_geteuid()); throw new InvalidArgumentException('logfile must be writeable by user: '******'name']); } else { if (!file_exists($filename)) { touch($filename); } } $this->filename = $filename; } else { throw new InvalidArgumentException("filename must be an absolute filename in a writeable directory : {$filename}"); } }
/** * Location of the template cache directory * * @param string $dir absolute location of the template cache directory * * @throws InvalidArgumentException * @return void */ public function setCacheDir($dir) { if (!is_dir($dir) && !Tools::mkdir($dir, false)) { throw new InvalidArgumentException(sprintf("Invalid directory, %s", $dir)); } else { if (!is_readable($dir)) { throw new InvalidArgumentException(sprintf("Directory %s not readable", $dir)); } else { if (!is_writable($dir)) { throw new InvalidArgumentException(sprintf("Directory %s not writable", $dir)); } else { $this->cacheDir = $dir; } } } }
/** * directory where the app data lives * * @param string $dir directory where the app data live * * @return void * @throws InvalidArgumentException */ public function setAppDir($dir) { if (!is_dir($dir) && !Tools::mkdir($dir, true)) { throw new InvalidArgumentException(sprintf("Invalid App directory, %s", $dir)); } else { if (!is_readable($dir)) { throw new InvalidArgumentException(sprintf("App Directory %s not readable", $dir)); } else { $this->app_dir = $dir; $classLoader = new SplClassLoader($dir); $classLoader->register(); } } }