You are here

public function WritableStreamBackupFile::write in Backup and Migrate 5.0.x

Write a line to the file.

Parameters

string $data: A string to write to the file.

Throws

\Exception

Overrides BackupFileWritableInterface::write

1 call to WritableStreamBackupFile::write()
WritableStreamBackupFile::writeAll in src/Core/File/WritableStreamBackupFile.php
Open the file, writes the given contents and closes it.

File

src/Core/File/WritableStreamBackupFile.php, line 56

Class

WritableStreamBackupFile
A file object which represents an existing PHP stream with read/write.

Namespace

Drupal\backup_migrate\Core\File

Code

public function write($data) {
  if (!$this
    ->isOpen()) {
    $this
      ->openForWrite();
  }
  if ($this->handle) {
    if (fwrite($this->handle, $data) === FALSE) {
      throw new \Exception('Cannot write to file: ' . $this
        ->realpath());
    }
    else {
      $this->dirty = TRUE;
    }
  }
  else {
    throw new \Exception('File not open for writing.');
  }
}