You are here

public function ReadableStreamBackupFile::openForRead in Backup and Migrate 5.0.x

Open a file for reading or writing.

Parameters

bool $binary: If true open as a binary file.

Return value

resource

Throws

\Exception

Overrides BackupFileReadableInterface::openForRead

3 calls to ReadableStreamBackupFile::openForRead()
ReadableStreamBackupFile::readAll in src/Core/File/ReadableStreamBackupFile.php
Read a line from the file.
ReadableStreamBackupFile::readBytes in src/Core/File/ReadableStreamBackupFile.php
Read a line from the file.
ReadableStreamBackupFile::readLine in src/Core/File/ReadableStreamBackupFile.php
Read a single line from the file.

File

src/Core/File/ReadableStreamBackupFile.php, line 77

Class

ReadableStreamBackupFile
Uses a readable PHP stream such as a local file.

Namespace

Drupal\backup_migrate\Core\File

Code

public function openForRead($binary = FALSE) {
  if (!$this
    ->isOpen()) {
    $path = $this
      ->realpath();
    if (!is_readable($path)) {

      // @todo Throw better exception
      throw new \Exception('Cannot read file.');
    }

    // Open the file.
    $mode = "r" . ($binary ? "b" : "");
    $this->handle = fopen($path, $mode);
    if (!$this->handle) {
      throw new \Exception('Cannot open file.');
    }
  }

  // If the file is already open, rewind it.
  $this
    ->rewind();
  return $this->handle;
}