Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / KeyValueStore / MemoryStorage.php
1 <?php
2
3 namespace Drupal\Core\KeyValueStore;
4
5 /**
6  * Defines a default key/value store implementation.
7  */
8 class MemoryStorage extends StorageBase {
9
10   /**
11    * The actual storage of key-value pairs.
12    *
13    * @var array
14    */
15   protected $data = [];
16
17   /**
18    * {@inheritdoc}
19    */
20   public function has($key) {
21     return array_key_exists($key, $this->data);
22   }
23
24   /**
25    * {@inheritdoc}
26    */
27   public function get($key, $default = NULL) {
28     return array_key_exists($key, $this->data) ? $this->data[$key] : $default;
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function getMultiple(array $keys) {
35     return array_intersect_key($this->data, array_flip($keys));
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function getAll() {
42     return $this->data;
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   public function set($key, $value) {
49     $this->data[$key] = $value;
50   }
51
52   /**
53    * {@inheritdoc}
54    */
55   public function setIfNotExists($key, $value) {
56     if (!isset($this->data[$key])) {
57       $this->data[$key] = $value;
58       return TRUE;
59     }
60     return FALSE;
61   }
62
63   /**
64    * {@inheritdoc}
65    */
66   public function setMultiple(array $data) {
67     $this->data = $data + $this->data;
68   }
69
70   /**
71    * {@inheritdoc}
72    */
73   public function rename($key, $new_key) {
74     $this->data[$new_key] = $this->data[$key];
75     unset($this->data[$key]);
76   }
77
78   /**
79    * {@inheritdoc}
80    */
81   public function delete($key) {
82     unset($this->data[$key]);
83   }
84
85   /**
86    * {@inheritdoc}
87    */
88   public function deleteMultiple(array $keys) {
89     foreach ($keys as $key) {
90       unset($this->data[$key]);
91     }
92   }
93
94   /**
95    * {@inheritdoc}
96    */
97   public function deleteAll() {
98     $this->data = [];
99   }
100
101 }