]> git.mxchange.org Git - friendica.git/blob - src/Core/Session/Capability/IHandleSessions.php
Merge pull request #12021 from nupplaphil/feat/session_util
[friendica.git] / src / Core / Session / Capability / IHandleSessions.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, 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\Capability;
23
24 /**
25  * Contains all global supported Session methods
26  */
27 interface IHandleSessions
28 {
29         /**
30          * Start the current session
31          *
32          * @return self The own Session instance
33          */
34         public function start(): IHandleSessions;
35
36         /**
37          * Checks if the key exists in this session
38          *
39          * @param string $name
40          *
41          * @return boolean True, if it exists
42          */
43         public function exists(string $name): bool;
44
45         /**
46          * Retrieves a key from the session super global or the defaults if the key is missing or the value is falsy.
47          *
48          * Handle the case where session_start() hasn't been called and the super global isn't available.
49          *
50          * @param string $name
51          * @param mixed  $defaults
52          *
53          * @return mixed
54          */
55         public function get(string $name, $defaults = null);
56
57         /**
58          * Retrieves a value from the provided key if it exists and removes it from session
59          *
60          * @param string $name
61          * @param mixed  $defaults
62          *
63          * @return mixed
64          */
65         public function pop(string $name, $defaults = null);
66
67         /**
68          * Sets a single session variable.
69          * Overrides value of existing key.
70          *
71          * @param string $name
72          * @param mixed  $value
73          */
74         public function set(string $name, $value);
75
76         /**
77          * Sets multiple session variables.
78          * Overrides values for existing keys.
79          *
80          * @param array $values
81          */
82         public function setMultiple(array $values);
83
84         /**
85          * Removes a session variable.
86          * Ignores missing keys.
87          *
88          * @param string $name
89          */
90         public function remove(string $name);
91
92         /**
93          * Clears the current session array
94          */
95         public function clear();
96 }