-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseSessionDriver.php
More file actions
113 lines (99 loc) · 2.5 KB
/
BaseSessionDriver.php
File metadata and controls
113 lines (99 loc) · 2.5 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
<?php
namespace FireSessions;
/**
* Base class for defining session drivers.
*
* This content is released under the MIT License (MIT).
* @see LICENSE file
*/
abstract class BaseSessionDriver implements \SessionHandlerInterface
{
/**
* @var array Associative array of setting names and values
*/
protected $config;
/**
* @var string Checksum of read session data, for avoiding unnecessary savings
*/
protected $sessionDataChecksum;
/**
* @var string The session ID when being opened; used for noticing session regenerations
*/
protected $initialSessionId;
/**
* @var mixed What value should the instance return in case of success
*/
private static $trueValue = 0;
/**
* @var mixed What value should the instance return in case of failure
*/
private static $falseValue = -1;
/**
* BaseSessionDriver constructor.
*
* @param array $config
*/
public function __construct(array $config)
{
$this->config = $config;
$isPHP7 = version_compare(PHP_VERSION, '7.0.0') >= 0;
$isPHP7 && self::$trueValue = true && ((self::$falseValue = false) === false);
}
/**
* Lock acquiring for this implementation.
*
* @param string $sessionId If required, this can be the session ID
* @return bool if the locking succeeded or not
*/
abstract protected function acquireLock($sessionId = null);
/**
* Releases the obtained lock over a session instance.
*
* @return bool Whether the unlocking succeeded or not
*/
abstract protected function releaseLock();
/**
* Destroys a session cookie.
*
* @return bool
*/
protected function destroyCookie()
{
return @setcookie(
$this->config['cookie_name'],
null,
1,
$this->config['cookie_path'],
$this->config['cookie_domain'],
$this->config['cookie_secure'],
true
);
}
/**
* Returns the user IP, used if 'match_ip' setting is enabled.
*
* @return string User IP
*/
protected function getIp()
{
return $_SERVER['REMOTE_ADDR'];
}
/**
* Success return value.
*
* @return mixed
*/
protected static function true()
{
return self::$trueValue;
}
/**
* Failure return value.
*
* @return mixed
*/
protected static function false()
{
return self::$falseValue;
}
}