1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Archivr; |
4
|
|
|
|
5
|
|
|
use Zend\Stdlib\ArraySerializableInterface; |
6
|
|
|
|
7
|
|
|
class VaultConfiguration implements ArraySerializableInterface |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* An arbitrary user-defined title that helps to identity a vault by some user-specific information. |
11
|
|
|
* |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
protected $title; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Identifier for the vault adapter to use. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $adapter; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Identifier for the lock adapter to use. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $lockAdapter = 'storage'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Identifier for the index merger to be used. |
32
|
|
|
* Refers to identifiers known to the IndexMergerFactory. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $indexMerger = 'standard'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Identifier for the conflict handler to use. |
40
|
|
|
* Refers to identifiers known to the ConflictHandlerFactory. |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $conflictHandler = 'panicking'; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Identifier for the operation list builder to use. |
48
|
|
|
* Refers to identifiers known to the OperationListBuilderFactory. |
49
|
|
|
* |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
protected $operationListBuilder = 'standard'; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Map with additional storageDriver- or lockAdapter-specific settings. |
56
|
|
|
* |
57
|
|
|
* @var array |
58
|
|
|
*/ |
59
|
|
|
protected $settings; |
60
|
|
|
|
61
|
|
|
public function __construct(string $storageDriver = 'unknown') |
62
|
|
|
{ |
63
|
|
|
$this->setAdapter($storageDriver); |
64
|
|
|
$this->setTitle($storageDriver); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getTitle(): string |
68
|
|
|
{ |
69
|
|
|
return $this->title; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function setTitle(string $title): VaultConfiguration |
73
|
|
|
{ |
74
|
|
|
$this->title = $title; |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getAdapter(): string |
80
|
|
|
{ |
81
|
|
|
return $this->adapter; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function setAdapter(string $adapter): VaultConfiguration |
85
|
|
|
{ |
86
|
|
|
$this->adapter = $adapter; |
87
|
|
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getLockAdapter(): string |
92
|
|
|
{ |
93
|
|
|
return $this->lockAdapter; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function setLockAdapter(string $lockAdapter): VaultConfiguration |
97
|
|
|
{ |
98
|
|
|
$this->lockAdapter = $lockAdapter; |
99
|
|
|
|
100
|
|
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getIndexMerger(): string |
104
|
|
|
{ |
105
|
|
|
return $this->indexMerger; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function setIndexMerger(string $indexMerger): VaultConfiguration |
109
|
|
|
{ |
110
|
|
|
$this->indexMerger = $indexMerger; |
111
|
|
|
|
112
|
|
|
return $this; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function getConflictHandler(): string |
116
|
|
|
{ |
117
|
|
|
return $this->conflictHandler; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function setConflictHandler(string $conflictHandler): VaultConfiguration |
121
|
|
|
{ |
122
|
|
|
$this->conflictHandler = $conflictHandler; |
123
|
|
|
|
124
|
|
|
return $this; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function getOperationListBuilder(): string |
128
|
|
|
{ |
129
|
|
|
return $this->operationListBuilder; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function setOperationListBuilder(string $operationListBuilder): VaultConfiguration |
133
|
|
|
{ |
134
|
|
|
$this->operationListBuilder = $operationListBuilder; |
135
|
|
|
|
136
|
|
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function getSettings(): array |
140
|
|
|
{ |
141
|
|
|
return $this->settings; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function getSetting(string $name) |
145
|
|
|
{ |
146
|
|
|
return isset($this->settings[$name]) ? $this->settings[$name] : null; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function setSettings(array $settings): VaultConfiguration |
150
|
|
|
{ |
151
|
|
|
$this->settings = $settings; |
152
|
|
|
|
153
|
|
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function setSetting(string $name, $value): VaultConfiguration |
157
|
|
|
{ |
158
|
|
|
$this->settings[$name] = $value; |
159
|
|
|
|
160
|
|
|
return $this; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* {@inheritdoc} |
165
|
|
|
*/ |
166
|
|
|
public function exchangeArray(array $array) |
167
|
|
|
{ |
168
|
|
View Code Duplication |
if ($diff = array_diff(array_keys($array), array_keys($this->getArrayCopy()))) |
|
|
|
|
169
|
|
|
{ |
170
|
|
|
throw new \InvalidArgumentException("Invalid index(es): " . implode(',', $diff)); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
foreach ($array as $key => $value) |
174
|
|
|
{ |
175
|
|
|
// using setter to prevent skipping validation |
176
|
|
|
call_user_func([$this, 'set' . ucfirst($key)], $value); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* {@inheritdoc} |
182
|
|
|
*/ |
183
|
|
|
public function getArrayCopy() |
184
|
|
|
{ |
185
|
|
|
return get_object_vars($this); |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.