class FileReadOnlyStorage

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/PhpStorage/FileReadOnlyStorage.php \Drupal\Component\PhpStorage\FileReadOnlyStorage
  2. 8.9.x core/lib/Drupal/Component/PhpStorage/FileReadOnlyStorage.php \Drupal\Component\PhpStorage\FileReadOnlyStorage
  3. 11.x core/lib/Drupal/Component/PhpStorage/FileReadOnlyStorage.php \Drupal\Component\PhpStorage\FileReadOnlyStorage

Reads code as regular PHP files, but won't write them.

Hierarchy

Expanded class hierarchy of FileReadOnlyStorage

1 file declares its use of FileReadOnlyStorage
FileStorageReadOnlyTest.php in core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php

File

core/lib/Drupal/Component/PhpStorage/FileReadOnlyStorage.php, line 8

Namespace

Drupal\Component\PhpStorage
View source
class FileReadOnlyStorage implements PhpStorageInterface {
  
  /**
   * The directory where the files should be stored.
   *
   * @var string
   */
  protected $directory;
  
  /**
   * Constructs this FileStorage object.
   *
   * @param $configuration
   *   An associative array, containing at least two keys (the rest are ignored):
   *   - directory: The directory where the files should be stored.
   *   - bin: The storage bin. Multiple storage objects can be instantiated with
   *   the same configuration, but for different bins.
   */
  public function __construct(array $configuration) {
    $this->directory = $configuration['directory'] . '/' . $configuration['bin'];
  }
  
  /**
   * {@inheritdoc}
   */
  public function exists($name) {
    return file_exists($this->getFullPath($name));
  }
  
  /**
   * {@inheritdoc}
   */
  public function load($name) {
    // The FALSE returned on failure is enough for the caller to handle this,
    // we do not want a warning too.
    return @(include_once $this->getFullPath($name)) !== FALSE;
  }
  
  /**
   * {@inheritdoc}
   */
  public function save($name, $code) {
    return FALSE;
  }
  
  /**
   * {@inheritdoc}
   */
  public function delete($name) {
    return FALSE;
  }
  
  /**
   * {@inheritdoc}
   */
  public function getFullPath($name) {
    return $this->directory . '/' . $name;
  }
  
  /**
   * {@inheritdoc}
   */
  public function writeable() {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and will be removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3155413', E_USER_DEPRECATED);
    return FALSE;
  }
  
  /**
   * {@inheritdoc}
   */
  public function deleteAll() {
    return FALSE;
  }
  
  /**
   * {@inheritdoc}
   */
  public function listAll() {
    $names = [];
    if (file_exists($this->directory)) {
      foreach (new \DirectoryIterator($this->directory) as $fileinfo) {
        if (!$fileinfo->isDot()) {
          $name = $fileinfo->getFilename();
          if ($name != '.htaccess') {
            $names[] = $name;
          }
        }
      }
    }
    return $names;
  }
  
  /**
   * {@inheritdoc}
   */
  public function garbageCollection() {
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
FileReadOnlyStorage::$directory protected property The directory where the files should be stored.
FileReadOnlyStorage::delete public function Overrides PhpStorageInterface::delete
FileReadOnlyStorage::deleteAll public function Overrides PhpStorageInterface::deleteAll
FileReadOnlyStorage::exists public function Overrides PhpStorageInterface::exists
FileReadOnlyStorage::garbageCollection public function Overrides PhpStorageInterface::garbageCollection
FileReadOnlyStorage::getFullPath public function Overrides PhpStorageInterface::getFullPath
FileReadOnlyStorage::listAll public function Overrides PhpStorageInterface::listAll
FileReadOnlyStorage::load public function Overrides PhpStorageInterface::load
FileReadOnlyStorage::save public function Overrides PhpStorageInterface::save
FileReadOnlyStorage::writeable public function Overrides PhpStorageInterface::writeable
FileReadOnlyStorage::__construct public function Constructs this FileStorage object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.