MemoryStorage.php in Drupal 9
File
core/lib/Drupal/Core/KeyValueStore/MemoryStorage.php
View source
<?php
namespace Drupal\Core\KeyValueStore;
class MemoryStorage extends StorageBase {
protected $data = [];
public function has($key) {
return array_key_exists($key, $this->data);
}
public function get($key, $default = NULL) {
return array_key_exists($key, $this->data) ? $this->data[$key] : $default;
}
public function getMultiple(array $keys) {
return array_intersect_key($this->data, array_flip($keys));
}
public function getAll() {
return $this->data;
}
public function set($key, $value) {
$this->data[$key] = $value;
}
public function setIfNotExists($key, $value) {
if (!isset($this->data[$key])) {
$this->data[$key] = $value;
return TRUE;
}
return FALSE;
}
public function setMultiple(array $data) {
$this->data = $data + $this->data;
}
public function rename($key, $new_key) {
$this->data[$new_key] = $this->data[$key];
unset($this->data[$key]);
}
public function delete($key) {
unset($this->data[$key]);
}
public function deleteMultiple(array $keys) {
foreach ($keys as $key) {
unset($this->data[$key]);
}
}
public function deleteAll() {
$this->data = [];
}
}