You are here

protected function Twig_Environment::writeCacheFile in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Twig/Environment.php \Twig_Environment::writeCacheFile()
1 call to Twig_Environment::writeCacheFile()
Twig_Environment::loadTemplate in vendor/Twig/Environment.php
Loads a template by name.

File

vendor/Twig/Environment.php, line 1231

Class

Twig_Environment
Stores the Twig configuration.

Code

protected function writeCacheFile($file, $content) {
  $dir = dirname($file);
  if (!is_dir($dir)) {
    if (false === @mkdir($dir, 0777, true) && !is_dir($dir)) {
      throw new RuntimeException(sprintf("Unable to create the cache directory (%s).", $dir));
    }
  }
  elseif (!is_writable($dir)) {
    throw new RuntimeException(sprintf("Unable to write in the cache directory (%s).", $dir));
  }
  $tmpFile = tempnam($dir, basename($file));
  if (false !== @file_put_contents($tmpFile, $content)) {

    // rename does not work on Win32 before 5.2.6
    if (@rename($tmpFile, $file) || @copy($tmpFile, $file) && unlink($tmpFile)) {
      @chmod($file, 0666 & ~umask());
      return;
    }
  }
  throw new RuntimeException(sprintf('Failed to write cache file "%s".', $file));
}