-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStaticSessionManager.php
More file actions
147 lines (135 loc) · 4.31 KB
/
Copy pathStaticSessionManager.php
File metadata and controls
147 lines (135 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
declare(strict_types=1);
/**
* Omatamix Session
*
* The MIT License (MIT)
*
* Copyright (c) 2021 Nicholas English
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Omatamix\Session;
use function session;
class StaticSessionManager
{
/**
* Starts or resumes a session.
*
* @return bool Returns true on success or false on failure.
*/
public static function start(): bool
{
return session()->start();
}
/**
* Stop a session and destroys all data.
*
* @return bool Returns true on success or false on failure.
*/
public function stop(): bool
{
return session()->stop();
}
/**
* Check to see if a session already exists.
*
* @return bool Returns true if one exists and false if not.
*/
public static function exists(): bool
{
return session()->exists();
}
/**
* Stop a session and destroys all data.
*
* @return bool Returns true on success or false on failure.
*/
public static function invalidate(): bool
{
return session()->invalidate();
}
/**
* Checks whether a value for the specified key exists in the session.
*
* @param string $key The key to check.
*
* @return bool Returns true if the key was found and false if not.
*/
public static function has(string $key): bool
{
return session()->has($key);
}
/**
* Returns the requested value from the session or, if not found, the
* specified default value.
*
* @param string $key The key to retrieve the value for.
* @param mixed $defaultValue The default value to return if the
* requested value cannot be found.
*
* @return mixed Returns the requested value or the default
* value.
*/
public static function get(string $key, $defaultValue = null): mixed
{
return session()->get($key, $defaultValue);
}
/**
* Returns the requested value and removes it from the session.
*
* This is identical to calling `get` first and then `remove` for the same
* key.
*
* @param string $key The key to retrieve and remove the value for.
* @param mixed $defaultValue The default value to return if the requested
* value cannot be found.
*
* @return mixed The requested value or the default value.
*/
public static function flash(string $key, $defaultValue = null): mixed
{
return session()->flash($key, $defaultValue);
}
/**
* Sets the value for the specified key to the given value.
*
* Any data that already exists for the specified key will be overwritten.
*
* @param string $key The key to set the value for.
* @param mixed $value The value to set.
*
* @return void Returns nothing.
*/
public static function put(string $key, $value): void
{
return session()->put($key, $value);
}
/**
* Removes the value for the specified key from the session.
*
* @param string $key The key to remove the value for.
*
* @return void Returns nothing.
*/
public function delete(string $key): void
{
return session()->delete($key);
}
}