You are here

class FlysystemBridge in Flysystem 8

Same name and namespace in other branches
  1. 7 src/FlysystemBridge.php \Drupal\flysystem\FlysystemBridge
  2. 3.x src/FlysystemBridge.php \Drupal\flysystem\FlysystemBridge
  3. 2.0.x src/FlysystemBridge.php \Drupal\flysystem\FlysystemBridge
  4. 3.0.x src/FlysystemBridge.php \Drupal\flysystem\FlysystemBridge

An adapter for Flysystem to StreamWrapperInterface.

Hierarchy

Expanded class hierarchy of FlysystemBridge

2 files declare their use of FlysystemBridge
FlysystemBridgeTest.php in tests/src/Unit/FlysystemBridgeTest.php
FlysystemServiceProviderTest.php in tests/src/Unit/FlysystemServiceProviderTest.php

File

src/FlysystemBridge.php, line 13

Namespace

Drupal\flysystem
View source
class FlysystemBridge extends FlysystemStreamWrapper implements StreamWrapperInterface {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public static function getType() {
    return StreamWrapperInterface::WRITE_VISIBLE;
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    $scheme = $this
      ->getProtocol();
    $name = (string) $this
      ->getFactory()
      ->getSettings($scheme)['name'];
    $default = $this
      ->t('Flysystem: @scheme', [
      '@scheme' => $scheme,
    ]);
    return $name !== '' ? $this
      ->t($name) : $default;
  }

  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    $scheme = $this
      ->getProtocol();
    $description = (string) $this
      ->getFactory()
      ->getSettings($scheme)['description'];
    $default = $this
      ->t('Flysystem: @scheme', [
      '@scheme' => $scheme,
    ]);
    return $description !== '' ? $this
      ->t($description) : $default;
  }

  /**
   * {@inheritdoc}
   */
  public function getUri() {
    return $this->uri;
  }

  /**
   * {@inheritdoc}
   */
  public function setUri($uri) {
    $this->uri = $uri;
  }

  /**
   * {@inheritdoc}
   */
  public function getExternalUrl() {
    return $this
      ->getFactory()
      ->getPlugin($this
      ->getProtocol())
      ->getExternalUrl($this->uri);
  }

  /**
   * {@inheritdoc}
   */
  public function realpath() {
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function dirname($uri = NULL) {
    if (!isset($uri)) {
      $uri = $this->uri;
    }
    list($scheme, $target) = explode('://', $uri, 2);
    return $scheme . '://' . ltrim(Util::dirname($target), '\\/');
  }

  /**
   * Returns the filesystem for a given scheme.
   *
   * @param string $scheme
   *   The scheme.
   *
   * @return \League\Flysystem\FilesystemInterface
   *   The filesystem for the scheme.
   */
  protected function getFilesystemForScheme($scheme) {
    if (!isset(static::$filesystems[$scheme])) {
      static::$filesystems[$scheme] = $this
        ->getFactory()
        ->getFilesystem($scheme);
      static::$config[$scheme] = static::$defaultConfiguration;
      static::$config[$scheme]['permissions']['dir']['public'] = 0777;
      static::registerPlugins($scheme, static::$filesystems[$scheme]);
    }
    return static::$filesystems[$scheme];
  }

  /**
   * {@inheritdoc}
   */
  protected function getFilesystem() {
    if (!isset($this->filesystem)) {
      $this->filesystem = $this
        ->getFilesystemForScheme($this
        ->getProtocol());
    }
    return $this->filesystem;
  }

  /**
   * Returns the filesystem factory.
   *
   * @return \Drupal\flysystem\FlysystemFactory
   *   The Flysystem factory.
   */
  protected function getFactory() {
    return \Drupal::service('flysystem_factory');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlysystemBridge::dirname public function Gets the name of the directory from a given path. Overrides StreamWrapperInterface::dirname
FlysystemBridge::getDescription public function Returns the description of the stream wrapper for use in the UI. Overrides StreamWrapperInterface::getDescription
FlysystemBridge::getExternalUrl public function Returns a web accessible URL for the resource. Overrides StreamWrapperInterface::getExternalUrl
FlysystemBridge::getFactory protected function Returns the filesystem factory.
FlysystemBridge::getFilesystem protected function
FlysystemBridge::getFilesystemForScheme protected function Returns the filesystem for a given scheme.
FlysystemBridge::getName public function Returns the name of the stream wrapper for use in the UI. Overrides StreamWrapperInterface::getName
FlysystemBridge::getType public static function Returns the type of stream wrapper. Overrides StreamWrapperInterface::getType
FlysystemBridge::getUri public function Returns the stream resource URI. Overrides StreamWrapperInterface::getUri
FlysystemBridge::realpath public function Returns canonical, absolute path of the resource. Overrides StreamWrapperInterface::realpath
FlysystemBridge::setUri public function Sets the absolute stream resource URI. Overrides StreamWrapperInterface::setUri
PhpStreamWrapperInterface::dir_closedir public function 1
PhpStreamWrapperInterface::dir_opendir public function 1
PhpStreamWrapperInterface::dir_readdir public function 1
PhpStreamWrapperInterface::dir_rewinddir public function 1
PhpStreamWrapperInterface::mkdir public function 2
PhpStreamWrapperInterface::rename public function 2
PhpStreamWrapperInterface::rmdir public function 2
PhpStreamWrapperInterface::stream_cast public function Retrieve the underlying stream resource. 1
PhpStreamWrapperInterface::stream_close public function Closes stream. 1
PhpStreamWrapperInterface::stream_eof public function 1
PhpStreamWrapperInterface::stream_flush public function 2
PhpStreamWrapperInterface::stream_lock public function 2
PhpStreamWrapperInterface::stream_metadata public function Sets metadata on the stream. 2
PhpStreamWrapperInterface::stream_open public function 2
PhpStreamWrapperInterface::stream_read public function 1
PhpStreamWrapperInterface::stream_seek public function Seeks to specific location in a stream. 1
PhpStreamWrapperInterface::stream_set_option public function Change stream options. 1
PhpStreamWrapperInterface::stream_stat public function 1
PhpStreamWrapperInterface::stream_tell public function 1
PhpStreamWrapperInterface::stream_truncate public function Truncate stream. 2
PhpStreamWrapperInterface::stream_write public function 2
PhpStreamWrapperInterface::unlink public function 2
PhpStreamWrapperInterface::url_stat public function 1
StreamWrapperInterface::ALL constant A filter that matches all wrappers.
StreamWrapperInterface::HIDDEN constant Defines the stream wrapper bit flag for a hidden file.
StreamWrapperInterface::LOCAL constant Refers to a local file system location.
StreamWrapperInterface::LOCAL_HIDDEN constant Hidden, readable and writable using local files.
StreamWrapperInterface::LOCAL_NORMAL constant Visible, readable and writable using local files.
StreamWrapperInterface::NORMAL constant This is the default 'type' flag. This does not include StreamWrapperInterface::LOCAL, because PHP grants a greater trust level to local files (for example, they can be used in an "include" statement, regardless of the…
StreamWrapperInterface::READ constant Wrapper is readable (almost always true).
StreamWrapperInterface::READ_VISIBLE constant Visible and read-only.
StreamWrapperInterface::VISIBLE constant Exposed in the UI and potentially web accessible.
StreamWrapperInterface::WRITE constant Wrapper is writable.
StreamWrapperInterface::WRITE_VISIBLE constant Visible, readable and writable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.