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