1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpab/phpab. (https://github.com/phpab/phpab) |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/phpab/phpab for the canonical source repository |
6
|
|
|
* @copyright Copyright (c) 2015-2016 phpab. (https://github.com/phpab/) |
7
|
|
|
* @license https://raw.githubusercontent.com/phpab/phpab/master/LICENSE.md MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace PhpAb\Storage\Adapter; |
11
|
|
|
|
12
|
|
|
use Zend\Session\Container; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* An adapter that makes use of zendframework/zend-session. |
16
|
|
|
* |
17
|
|
|
* @package PhpAb |
18
|
|
|
*/ |
19
|
|
|
class ZendSession implements AdapterInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var Container The session container used to store data. |
23
|
|
|
*/ |
24
|
|
|
private $container; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Initializes a new instance of this class. |
28
|
|
|
* |
29
|
|
|
* @param Container $container The container used to store data. |
30
|
|
|
*/ |
31
|
|
|
public function __construct(Container $container) |
32
|
|
|
{ |
33
|
|
|
$this->container = $container; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritDoc} |
38
|
|
|
* |
39
|
|
|
* @param string $identifier The tests identifier |
40
|
|
|
*/ |
41
|
|
|
public function has($identifier) |
42
|
|
|
{ |
43
|
|
|
return $this->container->offsetExists($identifier); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritDoc} |
48
|
|
|
* |
49
|
|
|
* @param string $identifier The tests identifier name |
50
|
|
|
*/ |
51
|
|
|
public function get($identifier) |
52
|
|
|
{ |
53
|
|
|
if (!$this->has($identifier)) { |
54
|
|
|
return null; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $this->container[$identifier]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritDoc} |
62
|
|
|
* |
63
|
|
|
* @param string $identifier The tests identifier |
64
|
|
|
* @param mixed $participation The participated variant |
65
|
|
|
*/ |
66
|
|
|
public function set($identifier, $participation) |
67
|
|
|
{ |
68
|
|
|
$this->container[$identifier] = $participation; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritDoc} |
73
|
|
|
*/ |
74
|
|
|
public function all() |
75
|
|
|
{ |
76
|
|
|
return $this->container->getArrayCopy(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritDoc} |
81
|
|
|
* |
82
|
|
|
* @param string $identifier The identifier of the test to remove. |
83
|
|
|
*/ |
84
|
|
|
public function remove($identifier) |
85
|
|
|
{ |
86
|
|
|
if (!$this->has($identifier)) { |
87
|
|
|
return null; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$removedValue = $this->container[$identifier]; |
91
|
|
|
|
92
|
|
|
unset($this->container[$identifier]); |
93
|
|
|
|
94
|
|
|
return $removedValue; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritDoc} |
99
|
|
|
*/ |
100
|
|
|
public function clear() |
101
|
|
|
{ |
102
|
|
|
$removedValues = $this->all(); |
103
|
|
|
|
104
|
|
|
$this->container->getManager()->getStorage()->clear($this->container->getName()); |
105
|
|
|
|
106
|
|
|
return $removedValues; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|