|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2014-2020 |
|
7
|
|
|
* @package MW |
|
8
|
|
|
* @subpackage Session |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Aimeos\MW\Session; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Managing session data using the TYPO3 session |
|
17
|
|
|
* |
|
18
|
|
|
* @package MW |
|
19
|
|
|
* @subpackage Session |
|
20
|
|
|
*/ |
|
21
|
|
|
class Typo3 extends Base implements \Aimeos\MW\Session\Iface |
|
22
|
|
|
{ |
|
23
|
|
|
private $user; |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Initializes the Typo3 session object. |
|
28
|
|
|
* |
|
29
|
|
|
* @param \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication $user Typo3 user object (FE or BE) |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct( \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication $user ) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->user = $user; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Sets a list of key/value pairs. |
|
39
|
|
|
* |
|
40
|
|
|
* @param array $values Associative list of key/value pairs |
|
41
|
|
|
* @return \Aimeos\MW\Session\Iface Session instance for method chaining |
|
42
|
|
|
*/ |
|
43
|
|
|
public function apply( array $values ) : Iface |
|
44
|
|
|
{ |
|
45
|
|
|
foreach( $values as $key => $value ) { |
|
46
|
|
|
$this->user->setKey( 'ses', $key, $value ); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$this->user->storeSessionData(); |
|
|
|
|
|
|
50
|
|
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Remove the given key from the session. |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $name Key of the requested value in the session |
|
58
|
|
|
* @return \Aimeos\MW\Session\Iface Session instance for method chaining |
|
59
|
|
|
*/ |
|
60
|
|
|
public function del( string $name ) : Iface |
|
61
|
|
|
{ |
|
62
|
|
|
$this->user->setKey( 'ses', $name, null ); |
|
63
|
|
|
$this->user->storeSessionData(); |
|
64
|
|
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Returns the value of the requested session key. |
|
70
|
|
|
* |
|
71
|
|
|
* If the returned value wasn't a string, it's decoded from its serialized |
|
72
|
|
|
* representation. |
|
73
|
|
|
* |
|
74
|
|
|
* @param string $name Key of the requested value in the session |
|
75
|
|
|
* @param mixed $default Value returned if requested key isn't found |
|
76
|
|
|
* @return mixed Value associated to the requested key |
|
77
|
|
|
*/ |
|
78
|
|
|
public function get( string $name, $default = null ) |
|
79
|
|
|
{ |
|
80
|
|
|
if( ( $value = $this->user->getSessionData( $name ) ) !== null ) { |
|
81
|
|
|
return $value; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return $default; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Remove the list of keys from the session. |
|
90
|
|
|
* |
|
91
|
|
|
* @param array $name Keys to remove from the session |
|
92
|
|
|
* @return \Aimeos\MW\Session\Iface Session instance for method chaining |
|
93
|
|
|
*/ |
|
94
|
|
|
public function remove( array $names ) : Iface |
|
95
|
|
|
{ |
|
96
|
|
|
foreach( $names as $name ) { |
|
97
|
|
|
$this->user->setKey( 'ses', $name, null ); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
$this->user->storeSessionData(); |
|
101
|
|
|
return $this; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Sets the value for the specified key. |
|
107
|
|
|
* |
|
108
|
|
|
* If the value isn't a string, it's encoded into a serialized representation |
|
109
|
|
|
* and decoded again when using the get() method. |
|
110
|
|
|
* |
|
111
|
|
|
* @param string $name Key to the value which should be stored in the session |
|
112
|
|
|
* @param mixed $value Value that should be associated with the given key |
|
113
|
|
|
* @return \Aimeos\MW\Session\Iface Session instance for method chaining |
|
114
|
|
|
*/ |
|
115
|
|
|
public function set( string $name, $value ) : Iface |
|
116
|
|
|
{ |
|
117
|
|
|
$this->user->setAndSaveSessionData( $name, $value ); |
|
118
|
|
|
return $this; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|