|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Storeman\Config; |
|
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 layout to use. |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $vaultLayout = 'amberjack'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Identifier for the vault adapter to use. |
|
33
|
|
|
* |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $adapter = 'unknown'; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Identifier for the lock adapter to use. |
|
40
|
|
|
* |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $lockAdapter = 'storage'; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Identifier for the index merger to be used. |
|
47
|
|
|
* |
|
48
|
|
|
* @var string |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $indexMerger = 'standard'; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Identifier for the conflict handler to use. |
|
54
|
|
|
* |
|
55
|
|
|
* @var string |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $conflictHandler = 'panicking'; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Identifier for the operation list builder to use. |
|
61
|
|
|
* |
|
62
|
|
|
* @var string |
|
63
|
|
|
*/ |
|
64
|
|
|
protected $operationListBuilder = 'standard'; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* The vault priority is used for cases where some data has to be read from a vault and a decision has to be made which vault to use. |
|
68
|
|
|
* |
|
69
|
|
|
* @var int |
|
70
|
|
|
*/ |
|
71
|
|
|
protected $priority = 0; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Map with additional component-specific settings. |
|
75
|
|
|
* |
|
76
|
|
|
* @var array |
|
77
|
|
|
*/ |
|
78
|
|
|
protected $settings = []; |
|
79
|
|
|
|
|
80
|
|
|
public function __construct(Configuration $configuration) |
|
81
|
|
|
{ |
|
82
|
|
|
$this->configuration = $configuration; |
|
83
|
|
|
$this->configuration->addVault($this); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function getConfiguration(): Configuration |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->configuration; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function getTitle(): string |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->title; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function setTitle(string $title): VaultConfiguration |
|
97
|
|
|
{ |
|
98
|
|
|
$this->title = $title; |
|
99
|
|
|
|
|
100
|
|
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function getVaultLayout(): string |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->vaultLayout; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function setVaultLayout(string $vaultLayout): VaultConfiguration |
|
109
|
|
|
{ |
|
110
|
|
|
$this->vaultLayout = $vaultLayout; |
|
111
|
|
|
|
|
112
|
|
|
return $this; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function getAdapter(): string |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->adapter; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function setAdapter(string $adapter): VaultConfiguration |
|
121
|
|
|
{ |
|
122
|
|
|
$this->adapter = $adapter; |
|
123
|
|
|
|
|
124
|
|
|
return $this; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function getLockAdapter(): string |
|
128
|
|
|
{ |
|
129
|
|
|
return $this->lockAdapter; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function setLockAdapter(string $lockAdapter): VaultConfiguration |
|
133
|
|
|
{ |
|
134
|
|
|
$this->lockAdapter = $lockAdapter; |
|
135
|
|
|
|
|
136
|
|
|
return $this; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function getIndexMerger(): string |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->indexMerger; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function setIndexMerger(string $indexMerger): VaultConfiguration |
|
145
|
|
|
{ |
|
146
|
|
|
$this->indexMerger = $indexMerger; |
|
147
|
|
|
|
|
148
|
|
|
return $this; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function getConflictHandler(): string |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->conflictHandler; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
public function setConflictHandler(string $conflictHandler): VaultConfiguration |
|
157
|
|
|
{ |
|
158
|
|
|
$this->conflictHandler = $conflictHandler; |
|
159
|
|
|
|
|
160
|
|
|
return $this; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
public function getOperationListBuilder(): string |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->operationListBuilder; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
public function setOperationListBuilder(string $operationListBuilder): VaultConfiguration |
|
169
|
|
|
{ |
|
170
|
|
|
$this->operationListBuilder = $operationListBuilder; |
|
171
|
|
|
|
|
172
|
|
|
return $this; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
public function getPriority(): int |
|
176
|
|
|
{ |
|
177
|
|
|
return $this->priority; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
public function setPriority(int $priority): VaultConfiguration |
|
181
|
|
|
{ |
|
182
|
|
|
$this->priority = $priority; |
|
183
|
|
|
|
|
184
|
|
|
return $this; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
public function getSettings(): array |
|
188
|
|
|
{ |
|
189
|
|
|
return $this->settings; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
public function hasSetting(string $name): bool |
|
193
|
|
|
{ |
|
194
|
|
|
return array_key_exists($name, $this->settings); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
public function getSetting(string $name) |
|
198
|
|
|
{ |
|
199
|
|
|
return array_key_exists($name, $this->settings) ? $this->settings[$name] : null; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
public function setSettings(array $settings): VaultConfiguration |
|
203
|
|
|
{ |
|
204
|
|
|
$this->settings = $settings; |
|
205
|
|
|
|
|
206
|
|
|
return $this; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
public function setSetting(string $name, $value): VaultConfiguration |
|
210
|
|
|
{ |
|
211
|
|
|
$this->settings[$name] = $value; |
|
212
|
|
|
|
|
213
|
|
|
return $this; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* {@inheritdoc} |
|
218
|
|
|
*/ |
|
219
|
|
|
public function exchangeArray(array $array) |
|
220
|
|
|
{ |
|
221
|
|
|
if ($diff = array_diff(array_keys($array), array_keys($this->getArrayCopy()))) |
|
222
|
|
|
{ |
|
223
|
|
|
throw new \InvalidArgumentException("Invalid index(es): " . implode(',', $diff)); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
foreach ($array as $key => $value) |
|
227
|
|
|
{ |
|
228
|
|
|
// using setter to prevent skipping validation |
|
229
|
|
|
call_user_func([$this, 'set' . ucfirst($key)], $value); |
|
230
|
|
|
} |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* {@inheritdoc} |
|
235
|
|
|
*/ |
|
236
|
|
|
public function getArrayCopy() |
|
237
|
|
|
{ |
|
238
|
|
|
$array = get_object_vars($this); |
|
239
|
|
|
|
|
240
|
|
|
unset($array['configuration']); |
|
241
|
|
|
|
|
242
|
|
|
return $array; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
public static function loadValidatorMetadata(ClassMetadata $metadata) |
|
246
|
|
|
{ |
|
247
|
|
|
$metadata->addPropertyConstraint('title', new Assert\NotBlank()); |
|
248
|
|
|
$metadata->addPropertyConstraint('adapter', new StoremanAssert\StorageAdapterExists()); |
|
249
|
|
|
$metadata->addPropertyConstraint('conflictHandler', new StoremanAssert\ConflictHandlerExists()); |
|
250
|
|
|
$metadata->addPropertyConstraint('indexMerger', new StoremanAssert\IndexMergerExists()); |
|
251
|
|
|
$metadata->addPropertyConstraint('lockAdapter', new StoremanAssert\LockAdapterExists()); |
|
252
|
|
|
$metadata->addPropertyConstraint('operationListBuilder', new StoremanAssert\OperationListBuilderExists()); |
|
253
|
|
|
} |
|
254
|
|
|
} |
|
255
|
|
|
|