Esempio n. 1
0
 /**
  * @param string $file
  * @param string $data
  * @param bool $secureFileManipulation
  * @return bool
  * @throws phpFastCacheIOException
  */
 protected function writefile($file, $data, $secureFileManipulation = false)
 {
     /**
      * @eventName CacheWriteFileOnDisk
      * @param ExtendedCacheItemPoolInterface $this
      * @param string $file
      * @param bool $secureFileManipulation
      *
      */
     $this->eventManager->dispatch('CacheWriteFileOnDisk', $this, $file, $secureFileManipulation);
     if ($secureFileManipulation) {
         $tmpFilename = Directory::getAbsolutePath(dirname($file) . '/tmp_' . md5(str_shuffle(uniqid($this->getDriverName(), false)) . str_shuffle(uniqid($this->getDriverName(), false))));
         $f = fopen($tmpFilename, 'w+');
         flock($f, LOCK_EX);
         $octetWritten = fwrite($f, $data);
         flock($f, LOCK_UN);
         fclose($f);
         if (!rename($tmpFilename, $file)) {
             throw new phpFastCacheIOException(sprintf('Failed to rename %s to %s', $tmpFilename, $file));
         }
     } else {
         $f = fopen($file, 'w+');
         $octetWritten = fwrite($f, $data);
         fclose($f);
     }
     return $octetWritten !== false;
 }