StorageBase.php

Same filename and directory in other branches
  1. 8.9.x core/lib/Drupal/Core/KeyValueStore/StorageBase.php
  2. 10 core/lib/Drupal/Core/KeyValueStore/StorageBase.php
  3. 11.x core/lib/Drupal/Core/KeyValueStore/StorageBase.php

Namespace

Drupal\Core\KeyValueStore

File

core/lib/Drupal/Core/KeyValueStore/StorageBase.php

View source
<?php

namespace Drupal\Core\KeyValueStore;


/**
 * Provides a base class for key/value storage implementations.
 */
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,
        ]);
    }

}

Classes

Title Deprecated Summary
StorageBase Provides a base class for key/value storage implementations.

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