|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2014-2025 |
|
6
|
|
|
* @package MW |
|
7
|
|
|
* @subpackage Session |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Base\Session; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Implementation using Symfony sessions. |
|
16
|
|
|
* |
|
17
|
|
|
* @package MW |
|
18
|
|
|
* @subpackage Session |
|
19
|
|
|
*/ |
|
20
|
|
|
class Symfony extends Base implements \Aimeos\Base\Session\Iface |
|
21
|
|
|
{ |
|
22
|
|
|
private \Symfony\Component\HttpFoundation\Session\SessionInterface $object; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Initializes the object. |
|
27
|
|
|
* |
|
28
|
|
|
* @param \Symfony\Component\HttpFoundation\Session\SessionInterface $object Symfony session object |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct( \Symfony\Component\HttpFoundation\Session\SessionInterface $object ) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->object = $object; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Remove the given key from the session. |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $name Key of the requested value in the session |
|
40
|
|
|
* @return \Aimeos\Base\Session\Iface Session instance for method chaining |
|
41
|
|
|
*/ |
|
42
|
|
|
public function del( string $name ) : Iface |
|
43
|
|
|
{ |
|
44
|
|
|
$this->object->remove( $name ); |
|
45
|
|
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Returns the value of the requested session key. |
|
51
|
|
|
* |
|
52
|
|
|
* If the returned value wasn't a string, it's decoded from its string representation. |
|
53
|
|
|
* |
|
54
|
|
|
* @param string $name Key of the requested value in the session |
|
55
|
|
|
* @param mixed $default Value returned if requested key isn't found |
|
56
|
|
|
* @return mixed Value associated to the requested key |
|
57
|
|
|
*/ |
|
58
|
|
|
public function get( string $name, $default = null ) |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->object->get( $name, $default ); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Sets the value for the specified key. |
|
66
|
|
|
* |
|
67
|
|
|
* If the value isn't a string, it's serialized and decoded again when using the get() method. |
|
68
|
|
|
* |
|
69
|
|
|
* @param string $name Key to the value which should be stored in the session |
|
70
|
|
|
* @param mixed $value Value that should be associated with the given key |
|
71
|
|
|
* @return \Aimeos\Base\Session\Iface Session instance for method chaining |
|
72
|
|
|
*/ |
|
73
|
|
|
public function set( string $name, $value ) : Iface |
|
74
|
|
|
{ |
|
75
|
|
|
$this->object->set( $name, $value ); |
|
76
|
|
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|