示例#1
0
 /**
  * Atomically dumps content into a file.
  *
  * @param  string  $filename The file to be written to.
  * @param  string  $content  The data to write into the file.
  * @param  integer $mode     The file mode (octal).
  * @throws IOException       If the file cannot be written to.
  */
 public function dumpFile($filename, $content, $mode = 0666)
 {
     $dir = dirname($filename);
     $dirFileInfo = new SplFileInfo($dir, $this->fs);
     if (!$dirFileInfo->isDir()) {
         $this->mkdir($dir);
     } elseif (!$dirFileInfo->isWritable()) {
         throw new IOException(sprintf('Unable to write in the %s directory\\n', $dir));
     }
     $this->remove($filename);
     try {
         $this->fs->storeBytes($content, array('filename' => $filename, 'type' => 'file'));
     } catch (\MongoCursorException $e) {
         throw new IOException(sprintf('Failed to write file "%s".', $filename));
     }
 }