]> git.mxchange.org Git - friendica.git/blob - src/Core/Session/Type/AbstractSession.php
Merge pull request #11106 from annando/issue-11101
[friendica.git] / src / Core / Session / Type / AbstractSession.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Core\Session\Type;
23
24 use Friendica\Core\Session\Capability\IHandleSessions;
25
26 /**
27  * Contains the base methods for $_SESSION interaction
28  */
29 class AbstractSession implements IHandleSessions
30 {
31         /**
32          * {@inheritDoc}
33          */
34         public function start(): IHandleSessions
35         {
36                 return $this;
37         }
38
39         /**
40          * {@inheritDoc}}
41          */
42         public function exists(string $name): bool
43         {
44                 return isset($_SESSION[$name]);
45         }
46
47         /**
48          * {@inheritDoc}
49          */
50         public function get(string $name, $defaults = null)
51         {
52                 return $_SESSION[$name] ?? $defaults;
53         }
54
55         /**
56          * {@inheritDoc}
57          */
58         public function set(string $name, $value)
59         {
60                 $_SESSION[$name] = $value;
61         }
62
63         /**
64          * {@inheritDoc}
65          */
66         public function setMultiple(array $values)
67         {
68                 $_SESSION = $values + $_SESSION;
69         }
70
71         /**
72          * {@inheritDoc}
73          */
74         public function remove(string $name)
75         {
76                 unset($_SESSION[$name]);
77         }
78
79         /**
80          * {@inheritDoc}
81          */
82         public function clear()
83         {
84                 $_SESSION = [];
85         }
86 }