You are here

class StreamDestination in Backup and Migrate 8.4

Class StreamDestination.

@package BackupMigrate\Core\Destination

Hierarchy

Expanded class hierarchy of StreamDestination

File

lib/backup_migrate_core/src/Destination/StreamDestination.php, line 16

Namespace

BackupMigrate\Core\Destination
View source
class StreamDestination extends PluginBase implements WritableDestinationInterface, ConfigurableInterface {

  /**
   * {@inheritdoc}
   */
  function saveFile(BackupFileReadableInterface $file) {
    $stream_uri = $this
      ->confGet('streamuri');
    if ($fp_out = fopen($stream_uri, 'w')) {
      $file
        ->openForRead();
      while ($data = $file
        ->readBytes(1024 * 512)) {
        fwrite($fp_out, $data);
      }
      fclose($fp_out);
      $file
        ->close();
    }
    else {
      throw new \Exception("Cannot open the file {$stream_uri} for writing");
    }
  }

  /**
   * {@inheritdoc}
   */
  public function checkWritable() {
    $stream_uri = $this
      ->confGet('streamuri');

    // The stream must exist.
    if (!file_exists($stream_uri)) {
      throw new DestinationNotWritableException('The file stream !uri does not exist.', [
        '%uri' => $stream_uri,
      ]);
    }

    // The stream must be writable.
    if (!file_exists($stream_uri)) {
      throw new DestinationNotWritableException('The file stream !uri cannot be written to.', [
        '%uri' => $stream_uri,
      ]);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getFile($id) {
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function loadFileMetadata(BackupFileInterface $file) {
    return $file;
  }

  /**
   * {@inheritdoc}
   */
  public function loadFileForReading(BackupFileInterface $file) {
    return $file;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigurableTrait::$config protected property The object's configuration object.
ConfigurableTrait::$init protected property The initial configuration. These configuration options can be overriden by the config options but will not be overwritten. If the object is re-configured after construction any missing configuration options will revert to these values.
ConfigurableTrait::confGet public function Get a specific value from the configuration.
ConfigurableTrait::config public function Get the configuration object for this item.
ConfigurableTrait::configDefaults public function Get the default values for the plugin. 10
ConfigurableTrait::configErrors public function Get any validation errors in the config.
ConfigurableTrait::configSchema public function Get a default (blank) schema. 10
ConfigurableTrait::setConfig public function Set the configuration for all plugins. 1
ConfigurableTrait::__construct public function 2
PluginBase::opWeight public function What is the weight of the given operation for this plugin. Overrides PluginInterface::opWeight
PluginBase::supportedOps public function Get a list of supported operations and their weight. Overrides PluginInterface::supportedOps 8
PluginBase::supportsOp public function Does this plugin implement the given operation. Overrides PluginInterface::supportsOp
StreamDestination::checkWritable public function 1
StreamDestination::getFile public function
StreamDestination::loadFileForReading public function
StreamDestination::loadFileMetadata public function
StreamDestination::saveFile function Save a file to the destination. Overrides WritableDestinationInterface::saveFile 2
TranslatableTrait::$translator protected property
TranslatableTrait::setTranslator public function
TranslatableTrait::t public function Translate the given string if there is a translator service available.