Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
9.09% |
1 / 11 |
CRAP | |
9.09% |
2 / 22 |
MemoryStorage | |
0.00% |
0 / 1 |
|
9.09% |
1 / 11 |
161.26 | |
9.09% |
2 / 22 |
has | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
get | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
|||
getMultiple | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
getAll | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
set | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
setIfNotExists | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
setMultiple | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
rename | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
delete | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
deleteMultiple | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
deleteAll | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
<?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(); | |
/** | |
* {@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 = array(); | |
} | |
} |