1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Storeman; |
4
|
|
|
|
5
|
|
|
use Storeman\Validation\Constraints as StoremanAssert; |
6
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
7
|
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata; |
8
|
|
|
use Zend\Stdlib\ArraySerializableInterface; |
9
|
|
|
|
10
|
|
|
class VaultConfiguration implements ArraySerializableInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var Configuration |
14
|
|
|
*/ |
15
|
|
|
protected $configuration; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* An arbitrary user-defined title that helps to identity a vault by some user-specific information. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $title = 'unknown'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Identifier for the vault adapter to use. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $adapter = 'unknown'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Identifier for the lock adapter to use. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $lockAdapter = 'storage'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Identifier for the index merger to be used. |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $indexMerger = 'standard'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Identifier for the conflict handler to use. |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $conflictHandler = 'panicking'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Identifier for the operation list builder to use. |
54
|
|
|
* |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
protected $operationListBuilder = 'standard'; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Map with additional storageAdapter- or lockAdapter-specific settings. |
61
|
|
|
* |
62
|
|
|
* @var array |
63
|
|
|
*/ |
64
|
|
|
protected $settings = []; |
65
|
|
|
|
66
|
|
|
public function __construct(Configuration $configuration) |
67
|
|
|
{ |
68
|
|
|
$this->configuration = $configuration; |
69
|
|
|
$this->configuration->addVault($this); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getConfiguration(): Configuration |
73
|
|
|
{ |
74
|
|
|
return $this->configuration; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getTitle(): string |
78
|
|
|
{ |
79
|
|
|
return $this->title; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function setTitle(string $title): VaultConfiguration |
83
|
|
|
{ |
84
|
|
|
$this->title = $title; |
85
|
|
|
|
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getAdapter(): string |
90
|
|
|
{ |
91
|
|
|
return $this->adapter; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function setAdapter(string $adapter): VaultConfiguration |
95
|
|
|
{ |
96
|
|
|
$this->adapter = $adapter; |
97
|
|
|
|
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function getLockAdapter(): string |
102
|
|
|
{ |
103
|
|
|
return $this->lockAdapter; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function setLockAdapter(string $lockAdapter): VaultConfiguration |
107
|
|
|
{ |
108
|
|
|
$this->lockAdapter = $lockAdapter; |
109
|
|
|
|
110
|
|
|
return $this; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function getIndexMerger(): string |
114
|
|
|
{ |
115
|
|
|
return $this->indexMerger; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function setIndexMerger(string $indexMerger): VaultConfiguration |
119
|
|
|
{ |
120
|
|
|
$this->indexMerger = $indexMerger; |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function getConflictHandler(): string |
126
|
|
|
{ |
127
|
|
|
return $this->conflictHandler; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function setConflictHandler(string $conflictHandler): VaultConfiguration |
131
|
|
|
{ |
132
|
|
|
$this->conflictHandler = $conflictHandler; |
133
|
|
|
|
134
|
|
|
return $this; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function getOperationListBuilder(): string |
138
|
|
|
{ |
139
|
|
|
return $this->operationListBuilder; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function setOperationListBuilder(string $operationListBuilder): VaultConfiguration |
143
|
|
|
{ |
144
|
|
|
$this->operationListBuilder = $operationListBuilder; |
145
|
|
|
|
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function getSettings(): array |
150
|
|
|
{ |
151
|
|
|
return $this->settings; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function getSetting(string $name) |
155
|
|
|
{ |
156
|
|
|
return isset($this->settings[$name]) ? $this->settings[$name] : null; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function setSettings(array $settings): VaultConfiguration |
160
|
|
|
{ |
161
|
|
|
$this->settings = $settings; |
162
|
|
|
|
163
|
|
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function setSetting(string $name, $value): VaultConfiguration |
167
|
|
|
{ |
168
|
|
|
$this->settings[$name] = $value; |
169
|
|
|
|
170
|
|
|
return $this; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* {@inheritdoc} |
175
|
|
|
*/ |
176
|
|
|
public function exchangeArray(array $array) |
177
|
|
|
{ |
178
|
|
|
if ($diff = array_diff(array_keys($array), array_keys($this->getArrayCopy()))) |
179
|
|
|
{ |
180
|
|
|
throw new \InvalidArgumentException("Invalid index(es): " . implode(',', $diff)); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
foreach ($array as $key => $value) |
184
|
|
|
{ |
185
|
|
|
// using setter to prevent skipping validation |
186
|
|
|
call_user_func([$this, 'set' . ucfirst($key)], $value); |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* {@inheritdoc} |
192
|
|
|
*/ |
193
|
|
|
public function getArrayCopy() |
194
|
|
|
{ |
195
|
|
|
$array = get_object_vars($this); |
196
|
|
|
|
197
|
|
|
unset($array['configuration']); |
198
|
|
|
|
199
|
|
|
return $array; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
public static function loadValidatorMetadata(ClassMetadata $metadata) |
203
|
|
|
{ |
204
|
|
|
$metadata->addPropertyConstraint('title', new Assert\NotBlank()); |
205
|
|
|
$metadata->addPropertyConstraint('adapter', new StoremanAssert\StorageAdapterExists()); |
206
|
|
|
$metadata->addPropertyConstraint('conflictHandler', new StoremanAssert\ConflictHandlerExists()); |
207
|
|
|
$metadata->addPropertyConstraint('indexMerger', new StoremanAssert\IndexMergerExists()); |
208
|
|
|
$metadata->addPropertyConstraint('lockAdapter', new StoremanAssert\LockAdapterExists()); |
209
|
|
|
$metadata->addPropertyConstraint('operationListBuilder', new StoremanAssert\OperationListBuilderExists()); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|