|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package presentation |
|
4
|
|
|
* @subpackage requests |
|
5
|
|
|
* @author marius orcsik <[email protected]> |
|
6
|
|
|
* @date 21.02.15 |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace vsc\presentation\requests; |
|
9
|
|
|
|
|
10
|
|
|
use vsc\infrastructure\vsc; |
|
11
|
|
|
|
|
12
|
|
|
trait SessionRequestTrait { |
|
13
|
|
|
protected $aSessionVars = []; |
|
14
|
|
|
|
|
15
|
17 |
|
protected function initSession() { |
|
16
|
17 |
|
if (static::hasSession() && isset($_SESSION)) { |
|
17
|
|
|
$this->aSessionVars = $_SESSION; |
|
18
|
|
|
} |
|
19
|
17 |
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @return bool |
|
23
|
|
|
*/ |
|
24
|
18 |
|
public static function hasSession() { |
|
25
|
18 |
|
return (session_id() != ''); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @return array |
|
30
|
|
|
*/ |
|
31
|
1 |
|
public function getSessionVars() { |
|
32
|
1 |
|
return $this->aSessionVars; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param string $sVarName |
|
37
|
|
|
* @return bool |
|
38
|
|
|
*/ |
|
39
|
1 |
|
public function hasSessionVar($sVarName) { |
|
40
|
|
|
return ( |
|
41
|
1 |
|
array_key_exists($sVarName, $this->aSessionVars) |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return string |
|
47
|
|
|
*/ |
|
48
|
1 |
|
public static function getSessionName() { |
|
49
|
1 |
|
return session_id(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param string $sSessionName |
|
|
|
|
|
|
54
|
|
|
* @throws ExceptionRequest |
|
55
|
|
|
*/ |
|
56
|
1 |
|
public static function startSession($sSessionName = null) { |
|
57
|
1 |
|
if (!static::hasSession()) { |
|
58
|
1 |
|
if (((double)PHP_VERSION >= 5.4 && session_status() == PHP_SESSION_DISABLED)) { |
|
59
|
|
|
throw new ExceptionRequest('Sessions are not available'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
if (((double)PHP_VERSION >= 5.4 && session_status() == PHP_SESSION_NONE)) { |
|
63
|
1 |
|
$oRequest = vsc::getEnv()->getHttpRequest(); |
|
64
|
1 |
|
if (!vsc::isCli()) { |
|
65
|
|
|
session_set_cookie_params(0, '/', $oRequest->getUriObject()->getHost(), HttpRequestA::isSecure(), true); |
|
66
|
|
|
} |
|
67
|
1 |
|
if (@session_start()) { |
|
68
|
1 |
|
$_SESSION = array(); |
|
69
|
1 |
|
if (!is_null($sSessionName)) { |
|
70
|
1 |
|
session_id($sSessionName); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
1 |
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* return void |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public static function destroySession() { |
|
81
|
1 |
|
$aSessionCookieParams = session_get_cookie_params(); |
|
82
|
|
|
|
|
83
|
1 |
|
setcookie(session_name(), "", -1, $aSessionCookieParams['path'], $aSessionCookieParams['domain'], $aSessionCookieParams['secure'], $aSessionCookieParams['httponly']); |
|
84
|
1 |
|
session_unset(); |
|
85
|
1 |
|
session_destroy(); |
|
86
|
1 |
|
session_write_close(); |
|
87
|
1 |
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $sVarName |
|
92
|
|
|
* @return mixed |
|
93
|
|
|
*/ |
|
94
|
2 |
View Code Duplication |
public function getSessionVar($sVarName) { |
|
|
|
|
|
|
95
|
2 |
|
if (array_key_exists($sVarName, $this->aSessionVars)) { |
|
96
|
1 |
|
return HttpRequestA::getDecodedVar($this->aSessionVars[$sVarName]); |
|
97
|
|
|
} else { |
|
98
|
1 |
|
return null; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param string $sVarName |
|
104
|
|
|
* @param string $sVarValue |
|
105
|
|
|
* @return bool |
|
106
|
|
|
*/ |
|
107
|
1 |
|
public function setSessionVar($sVarName, $sVarValue) { |
|
108
|
1 |
|
$this->aSessionVars[$sVarName] = $sVarValue; |
|
109
|
1 |
|
$_SESSION[$sVarName] = $sVarValue; |
|
110
|
1 |
|
return true; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.