]> git.mxchange.org Git - friendica.git/blob - src/Core/Session/AbstractSession.php
Merge pull request #7996 from annando/poco-cleanup
[friendica.git] / src / Core / Session / AbstractSession.php
1 <?php
2
3
4 namespace Friendica\Core\Session;
5
6 use Friendica\Model\User\Cookie;
7
8 /**
9  * Contains the base methods for $_SESSION interaction
10  */
11 class AbstractSession
12 {
13         /** @var Cookie */
14         protected $cookie;
15
16         public function __construct( Cookie $cookie)
17         {
18                 $this->cookie = $cookie;
19         }
20
21         /**
22          * {@inheritDoc}
23          */
24         public function start()
25         {
26                 return $this;
27         }
28
29         /**
30          * {@inheritDoc}}
31          */
32         public function exists(string $name)
33         {
34                 return isset($_SESSION[$name]);
35         }
36
37         /**
38          * {@inheritDoc}
39          */
40         public function get(string $name, $defaults = null)
41         {
42                 return $_SESSION[$name] ?? $defaults;
43         }
44
45         /**
46          * {@inheritDoc}
47          */
48         public function set(string $name, $value)
49         {
50                 $_SESSION[$name] = $value;
51         }
52
53         /**
54          * {@inheritDoc}
55          */
56         public function setMultiple(array $values)
57         {
58                 $_SESSION = $values + $_SESSION;
59         }
60
61         /**
62          * {@inheritDoc}
63          */
64         public function remove(string $name)
65         {
66                 unset($_SESSION[$name]);
67         }
68
69         /**
70          * {@inheritDoc}
71          */
72         public function clear()
73         {
74                 $_SESSION = [];
75         }
76 }