You are here

class ReplicateAdapter in Flysystem 7

@todo Remove after https://github.com/thephpleague/flysystem-replicate-adapter/pull/5

Hierarchy

  • class \Drupal\flysystem\Flysystem\Adapter\ReplicateAdapter extends \League\Flysystem\Replicate\ReplicateAdapter

Expanded class hierarchy of ReplicateAdapter

1 file declares its use of ReplicateAdapter
FlysystemFactory.php in src/FlysystemFactory.php
Contains \Drupal\flysystem\FlysystemFactory.

File

src/Flysystem/Adapter/ReplicateAdapter.php, line 18
Contains \Drupal\flysystem\Flysystem\Adapter\ReplicateAdapter.

Namespace

Drupal\flysystem\Flysystem\Adapter
View source
class ReplicateAdapter extends FlysystemReplicateAdapter {

  /**
   * {@inheritdoc}
   */
  public function updateStream($path, $resource, Config $config) {
    if (!$this->source
      ->updateStream($path, $resource, $config)) {
      return FALSE;
    }
    if (!($resource = $this
      ->ensureSeekable($resource, $path))) {
      return FALSE;
    }
    if ($this->replica
      ->has($path)) {
      return $this->replica
        ->updateStream($path, $resource, $config);
    }
    return $this->replica
      ->writeStream($path, $resource, $config);
  }

  /**
   * {@inheritdoc}
   */
  public function writeStream($path, $resource, Config $config) {
    if (!$this->source
      ->writeStream($path, $resource, $config)) {
      return FALSE;
    }
    if (!($resource = $this
      ->ensureSeekable($resource, $path))) {
      return FALSE;
    }
    return $this->replica
      ->writeStream($path, $resource, $config);
  }

  /**
   * Rewinds the stream, or returns the source stream if not seekable.
   *
   * @param resource $resource
   *   The resource to rewind.
   * @param string $path
   *   The path where the resource exists.
   *
   * @return resource
   *   A stream set to position zero.
   */
  protected function ensureSeekable($resource, $path) {
    if (Util::isSeekableStream($resource) && rewind($resource)) {
      return $resource;
    }
    $stream = $this->source
      ->readStream($path);
    return $stream ? $stream['stream'] : FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ReplicateAdapter::ensureSeekable protected function Rewinds the stream, or returns the source stream if not seekable.
ReplicateAdapter::updateStream public function
ReplicateAdapter::writeStream public function