You are here

abstract class StorageBase in Drupal 10

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

Provides a base class for key/value storage implementations.

Hierarchy

  • class \Drupal\Core\KeyValueStore\StorageBase implements \Drupal\Core\KeyValueStore\KeyValueStoreInterface

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 $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