You are here

protected function FileCache::writeFile in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/doctrine/cache/lib/Doctrine/Common/Cache/FileCache.php \Doctrine\Common\Cache\FileCache::writeFile()

Writes a string content to file in an atomic way.

Parameters

string $filename Path to the file where to write the data.:

string $content The content to write:

Return value

bool TRUE on success, FALSE if path cannot be created, if path is not writable or an any other error.

2 calls to FileCache::writeFile()
FilesystemCache::doSave in vendor/doctrine/cache/lib/Doctrine/Common/Cache/FilesystemCache.php
Puts data into the cache.
PhpFileCache::doSave in vendor/doctrine/cache/lib/Doctrine/Common/Cache/PhpFileCache.php
Puts data into the cache.

File

vendor/doctrine/cache/lib/Doctrine/Common/Cache/FileCache.php, line 201

Class

FileCache
Base file cache driver.

Namespace

Doctrine\Common\Cache

Code

protected function writeFile($filename, $content) {
  $filepath = pathinfo($filename, PATHINFO_DIRNAME);
  if (!$this
    ->createPathIfNeeded($filepath)) {
    return false;
  }
  if (!is_writable($filepath)) {
    return false;
  }
  $tmpFile = tempnam($filepath, 'swap');
  @chmod($tmpFile, 0666 & ~$this->umask);
  if (file_put_contents($tmpFile, $content) !== false) {
    if (@rename($tmpFile, $filename)) {
      return true;
    }
    @unlink($tmpFile);
  }
  return false;
}