class MemoryStorage in Drupal 9
Same name in this branch
- 9 core/lib/Drupal/Core/Config/MemoryStorage.php \Drupal\Core\Config\MemoryStorage
- 9 core/lib/Drupal/Core/KeyValueStore/MemoryStorage.php \Drupal\Core\KeyValueStore\MemoryStorage
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/KeyValueStore/MemoryStorage.php \Drupal\Core\KeyValueStore\MemoryStorage
Defines a default key/value store implementation.
Hierarchy
- class \Drupal\Core\KeyValueStore\StorageBase implements KeyValueStoreInterface
- class \Drupal\Core\KeyValueStore\MemoryStorage
Expanded class hierarchy of MemoryStorage
File
- core/
lib/ Drupal/ Core/ KeyValueStore/ MemoryStorage.php, line 8
Namespace
Drupal\Core\KeyValueStoreView source
class MemoryStorage extends StorageBase {
/**
* The actual storage of key-value pairs.
*
* @var array
*/
protected $data = [];
/**
* {@inheritdoc}
*/
public function has($key) {
return array_key_exists($key, $this->data);
}
/**
* {@inheritdoc}
*/
public function get($key, $default = NULL) {
return array_key_exists($key, $this->data) ? $this->data[$key] : $default;
}
/**
* {@inheritdoc}
*/
public function getMultiple(array $keys) {
return array_intersect_key($this->data, array_flip($keys));
}
/**
* {@inheritdoc}
*/
public function getAll() {
return $this->data;
}
/**
* {@inheritdoc}
*/
public function set($key, $value) {
$this->data[$key] = $value;
}
/**
* {@inheritdoc}
*/
public function setIfNotExists($key, $value) {
if (!isset($this->data[$key])) {
$this->data[$key] = $value;
return TRUE;
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function setMultiple(array $data) {
$this->data = $data + $this->data;
}
/**
* {@inheritdoc}
*/
public function rename($key, $new_key) {
$this->data[$new_key] = $this->data[$key];
unset($this->data[$key]);
}
/**
* {@inheritdoc}
*/
public function delete($key) {
unset($this->data[$key]);
}
/**
* {@inheritdoc}
*/
public function deleteMultiple(array $keys) {
foreach ($keys as $key) {
unset($this->data[$key]);
}
}
/**
* {@inheritdoc}
*/
public function deleteAll() {
$this->data = [];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MemoryStorage:: |
protected | property | The actual storage of key-value pairs. | |
MemoryStorage:: |
public | function |
Deletes an item from the key/value store. Overrides StorageBase:: |
|
MemoryStorage:: |
public | function |
Deletes all items from the key/value store. Overrides KeyValueStoreInterface:: |
|
MemoryStorage:: |
public | function |
Deletes multiple items from the key/value store. Overrides KeyValueStoreInterface:: |
|
MemoryStorage:: |
public | function |
Returns the stored value for a given key. Overrides StorageBase:: |
|
MemoryStorage:: |
public | function |
Returns all stored key/value pairs in the collection. Overrides KeyValueStoreInterface:: |
|
MemoryStorage:: |
public | function |
Returns the stored key/value pairs for a given set of keys. Overrides KeyValueStoreInterface:: |
|
MemoryStorage:: |
public | function |
Returns whether a given key exists in the store. Overrides KeyValueStoreInterface:: |
|
MemoryStorage:: |
public | function |
Renames a key. Overrides KeyValueStoreInterface:: |
|
MemoryStorage:: |
public | function |
Saves a value for a given key. Overrides KeyValueStoreInterface:: |
|
MemoryStorage:: |
public | function |
Saves a value for a given key if it does not exist yet. Overrides KeyValueStoreInterface:: |
|
MemoryStorage:: |
public | function |
Saves key/value pairs. Overrides StorageBase:: |
|
StorageBase:: |
protected | property | The name of the collection holding key and value pairs. | |
StorageBase:: |
public | function |
Returns the name of this collection. Overrides KeyValueStoreInterface:: |
|
StorageBase:: |
public | function | 1 |