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\Session\Zend; |
22
|
|
|
|
23
|
|
|
use PSR7Sessions\Storageless\Session\SessionInterface; |
24
|
|
|
use Zend\Expressive\Session\SessionInterface as ZendSessionInterface; |
25
|
|
|
use function sprintf; |
26
|
|
|
|
27
|
|
|
final class SessionAdapter implements ZendSessionInterface |
28
|
|
|
{ |
29
|
|
|
/** @var SessionInterface */ |
30
|
|
|
private $session; |
31
|
|
|
|
32
|
|
|
public function __construct(SessionInterface $session) |
33
|
|
|
{ |
34
|
|
|
$this->session = $session; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
|
|
public function toArray() : array |
41
|
|
|
{ |
42
|
|
|
return (array) $this->session->jsonSerialize(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param mixed $default |
47
|
|
|
* @return mixed |
48
|
|
|
*/ |
49
|
|
|
public function get(string $name, $default = null) |
50
|
|
|
{ |
51
|
|
|
return $this->session->get($name, $default); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function has(string $name) : bool |
55
|
|
|
{ |
56
|
|
|
return $this->session->has($name); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param mixed $value |
61
|
|
|
*/ |
62
|
|
|
public function set(string $name, $value) : void |
63
|
|
|
{ |
64
|
|
|
$this->session->set($name, $value); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function unset(string $name) : void |
68
|
|
|
{ |
69
|
|
|
$this->session->remove($name); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function clear() : void |
73
|
|
|
{ |
74
|
|
|
$this->session->clear(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function hasChanged() : bool |
78
|
|
|
{ |
79
|
|
|
return $this->session->hasChanged(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* |
84
|
|
|
* @throws \BadMethodCallException |
85
|
|
|
*/ |
86
|
|
|
public function regenerate() : ZendSessionInterface |
87
|
|
|
{ |
88
|
|
|
throw new \BadMethodCallException(sprintf('Method "%s" not implemented', __METHOD__)); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function isRegenerated() : bool |
92
|
|
|
{ |
93
|
|
|
return false; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|