]> git.mxchange.org Git - friendica.git/blob - src/Core/Session/Memory.php
Renaming class
[friendica.git] / src / Core / Session / Memory.php
1 <?php
2
3 namespace Friendica\Core\Session;
4
5 /**
6  * Usable for backend processes (daemon/worker) and testing
7  */
8 final class Memory implements ISession
9 {
10         private $data = [];
11
12         public function start()
13         {
14                 // Backward compatibility until all Session variables are replaced
15                 // with the Session class
16                 $_SESSION = [];
17                 $this->clear();
18                 return $this;
19         }
20
21         /**
22          * @inheritDoc
23          */
24         public function exists(string $name)
25         {
26                 return isset($this->data[$name]);
27         }
28
29         /**
30          * @inheritDoc
31          */
32         public function get(string $name, $defaults = null)
33         {
34                 return $this->data[$name] ?? $defaults;
35         }
36
37         /**
38          * @inheritDoc
39          */
40         public function set(string $name, $value)
41         {
42                 $this->data[$name] = $value;
43         }
44
45         /**
46          * @inheritDoc
47          */
48         public function setMultiple(array $values)
49         {
50                 foreach ($values as $key => $value) {
51                         $this->data[$key] = $value;
52                 }
53         }
54
55         /**
56          * @inheritDoc
57          */
58         public function remove(string $name)
59         {
60                 if ($this->exists($name)) {
61                         unset($this->data[$name]);
62                         return true;
63                 }
64
65                 return false;
66         }
67
68         /**
69          * @inheritDoc
70          */
71         public function clear()
72         {
73                 $this->data = [];
74                 return true;
75         }
76
77         /**
78          * @inheritDoc
79          */
80         public function delete()
81         {
82                 $this->data = [];
83                 return true;
84         }
85 }