Passed
Push — master ( 781785...834e6a )
by Aimeos
05:51
created

Laravel5::apply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2020
6
 * @package MW
7
 * @subpackage Session
8
 */
9
10
11
namespace Aimeos\MW\Session;
12
13
14
/**
15
 * Implementation using Laravel 5 sessions.
16
 *
17
 * @package MW
18
 * @subpackage Session
19
 */
20
class Laravel5 extends Base implements \Aimeos\MW\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\MW\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\MW\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->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\MW\Session\Iface Session instance for method chaining
98
	 */
99
	public function remove( array $names ) : Iface
100
	{
101
		$this->object->forget( $names );
102
		return $this;
103
	}
104
105
106
	/**
107
	 * Sets the value for the specified key.
108
	 *
109
	 * If the value isn't a string, it's serialized 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->object->put( $name, $value );
118
		return $this;
119
	}
120
}
121