Newer
Older
<?php
/**
* @file
* Contains Drupal\Core\KeyValueStore\MemoryStorage.
*/
namespace Drupal\Core\KeyValueStore;
/**
* Defines a default key/value store implementation.
*/
class MemoryStorage extends StorageBase {
/**
* The actual storage of key-value pairs.
*
* @var array
*/
protected $data = array();
/**
* Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::get().
*/
public function get($key) {
Dries Buytaert
committed
return array_key_exists($key, $this->data) ? $this->data[$key] : NULL;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
}
/**
* Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::getMultiple().
*/
public function getMultiple(array $keys) {
return array_intersect_key($this->data, array_flip($keys));
}
/**
* Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::getAll().
*/
public function getAll() {
return $this->data;
}
/**
* Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::set().
*/
public function set($key, $value) {
$this->data[$key] = $value;
}
/**
* Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::setMultiple().
*/
public function setMultiple(array $data) {
$this->data = $data + $this->data;
}
/**
* Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::delete().
*/
public function delete($key) {
unset($this->data[$key]);
}
/**
* Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::deleteMultiple().
*/
public function deleteMultiple(array $keys) {
foreach ($keys as $key) {
unset($this->data[$key]);
}
}
}