You are here

abstract class StorageBase in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/KeyValueStore/StorageBase.php \Drupal\Core\KeyValueStore\StorageBase

Provides a base class for key/value storage implementations.

Hierarchy

Expanded class hierarchy of StorageBase

File

core/lib/Drupal/Core/KeyValueStore/StorageBase.php, line 8

Namespace

Drupal\Core\KeyValueStore
View source
abstract class StorageBase implements KeyValueStoreInterface {

  /**
   * The name of the collection holding key and value pairs.
   *
   * @var string
   */
  protected $collection;

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

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

  /**
   * {@inheritdoc}
   */
  public function get($key, $default = NULL) {
    $values = $this
      ->getMultiple([
      $key,
    ]);
    return isset($values[$key]) ? $values[$key] : $default;
  }

  /**
   * {@inheritdoc}
   */
  public function setMultiple(array $data) {
    foreach ($data as $key => $value) {
      $this
        ->set($key, $value);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function delete($key) {
    $this
      ->deleteMultiple([
      $key,
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
KeyValueStoreInterface::deleteAll public function Deletes all items from the key/value store. 3
KeyValueStoreInterface::deleteMultiple public function Deletes multiple items from the key/value store. 3
KeyValueStoreInterface::getAll public function Returns all stored key/value pairs in the collection. 3
KeyValueStoreInterface::getMultiple public function Returns the stored key/value pairs for a given set of keys. 3
KeyValueStoreInterface::has public function Returns whether a given key exists in the store. 3
KeyValueStoreInterface::rename public function Renames a key. 3
KeyValueStoreInterface::set public function Saves a value for a given key. 3
KeyValueStoreInterface::setIfNotExists public function Saves a value for a given key if it does not exist yet. 3
StorageBase::$collection protected property The name of the collection holding key and value pairs.
StorageBase::delete public function Deletes an item from the key/value store. Overrides KeyValueStoreInterface::delete 1
StorageBase::get public function Returns the stored value for a given key. Overrides KeyValueStoreInterface::get 1
StorageBase::getCollectionName public function Returns the name of this collection. Overrides KeyValueStoreInterface::getCollectionName
StorageBase::setMultiple public function Saves key/value pairs. Overrides KeyValueStoreInterface::setMultiple 1
StorageBase::__construct public function 1