Twig_Environment::writeCacheFile PHP Method

writeCacheFile() protected method

protected writeCacheFile ( $file, $content )
    protected function writeCacheFile($file, $content)
    {
        if (!is_dir(dirname($file))) {
            mkdir(dirname($file), 0777, true);
        }

        $tmpFile = tempnam(dirname($file), 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, 0644);

                return;
            }
        }

        throw new Twig_Error_Runtime(sprintf('Failed to write cache file "%s".', $file));
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * write apc-cache()
  *
  * @param $file
  * @param $content
  */
 protected function writeCacheFile($file, $content)
 {
     parent::writeCacheFile($file, $content);
     // Compile cached-file into bytecode-cache
     if (function_exists('apc_compile_file') === true) {
         apc_compile_file($file);
     }
 }