1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
declare(strict_types = 1); |
20
|
|
|
|
21
|
|
|
namespace PSR7Sessions\Storageless\Helper; |
22
|
|
|
|
23
|
|
|
use PSR7Sessions\Storageless\Session\SessionInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class ArrayAccessor. |
27
|
|
|
* |
28
|
|
|
* ArrayAccess Wrapper for SessionInterface |
29
|
|
|
*/ |
30
|
|
|
class ArrayAccessor implements \ArrayAccess |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @var SessionInterface |
34
|
|
|
*/ |
35
|
|
|
private $session; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* ArrayAccessor constructor. |
39
|
|
|
* |
40
|
|
|
* @param SessionInterface $session |
41
|
|
|
*/ |
42
|
5 |
|
public function __construct(SessionInterface $session) |
43
|
|
|
{ |
44
|
5 |
|
$this->session = $session; |
45
|
5 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
1 |
|
public function offsetExists($offset) : bool |
51
|
|
|
{ |
52
|
1 |
|
return $this->session->has($offset); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Offset to retrieve. |
57
|
|
|
* |
58
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetget.php |
59
|
|
|
* |
60
|
|
|
* @param string $offset |
61
|
|
|
* @param null $default |
62
|
|
|
* |
63
|
|
|
* @return array|bool|float|int|mixed|string |
64
|
|
|
*/ |
65
|
1 |
|
public function offsetGet($offset, $default = null) |
66
|
|
|
{ |
67
|
1 |
|
return $this->session->get($offset, $default); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
1 |
|
public function offsetSet($offset, $value) |
74
|
|
|
{ |
75
|
1 |
|
return $this->session->set($offset, $value); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
1 |
|
public function offsetUnset($offset) |
82
|
|
|
{ |
83
|
1 |
|
return $this->session->remove($offset); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return SessionInterface |
88
|
|
|
*/ |
89
|
1 |
|
public function getSession(): SessionInterface |
90
|
|
|
{ |
91
|
1 |
|
return $this->session; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|