interface KeyValueStoreInterface

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/KeyValueStore/KeyValueStoreInterface.php \Drupal\Core\KeyValueStore\KeyValueStoreInterface
  2. 10 core/lib/Drupal/Core/KeyValueStore/KeyValueStoreInterface.php \Drupal\Core\KeyValueStore\KeyValueStoreInterface
  3. 11.x core/lib/Drupal/Core/KeyValueStore/KeyValueStoreInterface.php \Drupal\Core\KeyValueStore\KeyValueStoreInterface

Defines the interface for key/value store implementations.

Hierarchy

Expanded class hierarchy of KeyValueStoreInterface

All classes that implement KeyValueStoreInterface

9 files declare their use of KeyValueStoreInterface
EntityAutocompleteController.php in core/modules/system/src/Controller/EntityAutocompleteController.php
EntityFieldManagerTest.php in core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php
Contains \Drupal\Tests\Core\Entity\EntityFieldManagerTest.
FieldDefinitionListenerTest.php in core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php
KeyValueEntityStorage.php in core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php
MigrateSourceTest.php in core/modules/migrate/tests/src/Unit/MigrateSourceTest.php
Contains \Drupal\Tests\migrate\Unit\MigrateSourceTest.

... See full list

File

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

Namespace

Drupal\Core\KeyValueStore
View source
interface KeyValueStoreInterface {
    
    /**
     * Returns the name of this collection.
     *
     * @return string
     *   The name of this collection.
     */
    public function getCollectionName();
    
    /**
     * Returns whether a given key exists in the store.
     *
     * @param string $key
     *   The key to check.
     *
     * @return bool
     *   TRUE if the key exists, FALSE otherwise.
     */
    public function has($key);
    
    /**
     * Returns the stored value for a given key.
     *
     * @param string $key
     *   The key of the data to retrieve.
     * @param mixed $default
     *   The default value to use if the key is not found.
     *
     * @return mixed
     *   The stored value, or the default value if no value exists.
     */
    public function get($key, $default = NULL);
    
    /**
     * Returns the stored key/value pairs for a given set of keys.
     *
     * @param array $keys
     *   A list of keys to retrieve.
     *
     * @return array
     *   An associative array of items successfully returned, indexed by key.
     *
     * @todo Determine the best return value for non-existing keys in
     *   https://www.drupal.org/node/2787737
     */
    public function getMultiple(array $keys);
    
    /**
     * Returns all stored key/value pairs in the collection.
     *
     * @return array
     *   An associative array containing all stored items in the collection.
     */
    public function getAll();
    
    /**
     * Saves a value for a given key.
     *
     * @param string $key
     *   The key of the data to store.
     * @param mixed $value
     *   The data to store.
     */
    public function set($key, $value);
    
    /**
     * Saves a value for a given key if it does not exist yet.
     *
     * @param string $key
     *   The key of the data to store.
     * @param mixed $value
     *   The data to store.
     *
     * @return bool
     *   TRUE if the data was set, FALSE if it already existed.
     */
    public function setIfNotExists($key, $value);
    
    /**
     * Saves key/value pairs.
     *
     * @param array $data
     *   An associative array of key/value pairs.
     */
    public function setMultiple(array $data);
    
    /**
     * Renames a key.
     *
     * @param string $key
     *   The key to rename.
     * @param string $new_key
     *   The new key name.
     */
    public function rename($key, $new_key);
    
    /**
     * Deletes an item from the key/value store.
     *
     * @param string $key
     *   The item name to delete.
     */
    public function delete($key);
    
    /**
     * Deletes multiple items from the key/value store.
     *
     * @param array $keys
     *   A list of item names to delete.
     */
    public function deleteMultiple(array $keys);
    
    /**
     * Deletes all items from the key/value store.
     */
    public function deleteAll();

}

Members

Title Sort descending Modifiers Object type Summary Overrides
KeyValueStoreInterface::delete public function Deletes an item from the key/value store. 2
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::get public function Returns the stored value for a given key. 2
KeyValueStoreInterface::getAll public function Returns all stored key/value pairs in the collection. 3
KeyValueStoreInterface::getCollectionName public function Returns the name of this collection. 2
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
KeyValueStoreInterface::setMultiple public function Saves key/value pairs. 2

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