You are here

abstract class StorageBase in Service Container 7

Same name and namespace in other branches
  1. 7.2 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

lib/Drupal/Core/KeyValueStore/StorageBase.php, line 13
Contains \Drupal\Core\KeyValueStore\StorageBase.

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;

  /**
   * Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::__construct().
   */
  public function __construct($collection) {
    $this->collection = $collection;
  }

  /**
   * Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::getCollectionName().
   */
  public function getCollectionName() {
    return $this->collection;
  }

  /**
   * Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::get().
   */
  public function get($key, $default = NULL) {
    $values = $this
      ->getMultiple(array(
      $key,
    ));
    return isset($values[$key]) ? $values[$key] : $default;
  }

  /**
   * Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::setMultiple().
   */
  public function setMultiple(array $data) {
    foreach ($data as $key => $value) {
      $this
        ->set($key, $value);
    }
  }

  /**
   * Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::delete().
   */
  public function delete($key) {
    $this
      ->deleteMultiple(array(
      $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 Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::delete(). Overrides KeyValueStoreInterface::delete 1
StorageBase::get public function Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::get(). Overrides KeyValueStoreInterface::get 1
StorageBase::getCollectionName public function Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::getCollectionName(). Overrides KeyValueStoreInterface::getCollectionName
StorageBase::setMultiple public function Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::setMultiple(). Overrides KeyValueStoreInterface::setMultiple 1
StorageBase::__construct public function Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::__construct(). 1