1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Flying\Struct; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Cache\ArrayCache; |
6
|
|
|
use Doctrine\Common\Cache\Cache; |
7
|
|
|
use Flying\Struct\Configuration\NamespacesMap; |
8
|
|
|
use Flying\Struct\Metadata\AnnotationParser; |
9
|
|
|
use Flying\Struct\Metadata\MetadataManager; |
10
|
|
|
use Flying\Struct\Metadata\MetadataManagerInterface; |
11
|
|
|
use Flying\Struct\Metadata\MetadataParserInterface; |
12
|
|
|
use Flying\Struct\Storage\ArrayBackend; |
13
|
|
|
use Flying\Struct\Storage\BackendInterface; |
14
|
|
|
use Flying\Struct\Storage\Storage; |
15
|
|
|
use Flying\Struct\Storage\StorageInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Structures configuration |
19
|
|
|
*/ |
20
|
|
|
class Configuration |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Cache for structures information |
24
|
|
|
* |
25
|
|
|
* @var Cache |
26
|
|
|
*/ |
27
|
|
|
private $cache; |
28
|
|
|
/** |
29
|
|
|
* Namespaces map for structure classes |
30
|
|
|
* |
31
|
|
|
* @var NamespacesMap |
32
|
|
|
*/ |
33
|
|
|
private $structNsMap; |
34
|
|
|
/** |
35
|
|
|
* Namespaces map for property classes |
36
|
|
|
* |
37
|
|
|
* @var NamespacesMap |
38
|
|
|
*/ |
39
|
|
|
private $propertyNsMap; |
40
|
|
|
/** |
41
|
|
|
* Namespaces map for annotation classes |
42
|
|
|
* |
43
|
|
|
* @var NamespacesMap |
44
|
|
|
*/ |
45
|
|
|
private $annotationNsMap; |
46
|
|
|
/** |
47
|
|
|
* Structures metadata manager |
48
|
|
|
* |
49
|
|
|
* @var MetadataManagerInterface |
50
|
|
|
*/ |
51
|
|
|
private $metadataManager; |
52
|
|
|
/** |
53
|
|
|
* Structures metadata parser |
54
|
|
|
* |
55
|
|
|
* @var MetadataParserInterface |
56
|
|
|
*/ |
57
|
|
|
private $metadataParser; |
58
|
|
|
/** |
59
|
|
|
* Structures storage manager |
60
|
|
|
* |
61
|
|
|
* @var StorageInterface |
62
|
|
|
*/ |
63
|
|
|
private $storage; |
64
|
|
|
/** |
65
|
|
|
* Backend for structures storage |
66
|
|
|
* |
67
|
|
|
* @var BackendInterface |
68
|
|
|
*/ |
69
|
|
|
private $storageBackend; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get cache for structures information |
73
|
|
|
* |
74
|
|
|
* @return Cache |
75
|
|
|
*/ |
76
|
184 |
|
public function getCache() |
77
|
|
|
{ |
78
|
184 |
|
if (!$this->cache) { |
79
|
184 |
|
$this->cache = new ArrayCache(); |
80
|
184 |
|
} |
81
|
184 |
|
return $this->cache; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Set cache for structures information |
86
|
|
|
* |
87
|
|
|
* @param Cache $cache |
88
|
|
|
* @return $this |
89
|
|
|
*/ |
90
|
|
|
public function setCache(Cache $cache) |
91
|
|
|
{ |
92
|
|
|
$this->cache = $cache; |
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get namespaces map for structure classes |
98
|
|
|
* |
99
|
|
|
* @return NamespacesMap |
100
|
|
|
* @throws \InvalidArgumentException |
101
|
|
|
*/ |
102
|
198 |
|
public function getStructNamespacesMap() |
103
|
|
|
{ |
104
|
198 |
|
if (!$this->structNsMap) { |
105
|
198 |
|
$this->structNsMap = new NamespacesMap(); |
106
|
198 |
|
$this->structNsMap->add('Flying\Struct', 'default'); |
107
|
198 |
|
} |
108
|
198 |
|
return $this->structNsMap; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get namespaces map for property classes |
113
|
|
|
* |
114
|
|
|
* @return NamespacesMap |
115
|
|
|
* @throws \InvalidArgumentException |
116
|
|
|
*/ |
117
|
194 |
|
public function getPropertyNamespacesMap() |
118
|
|
|
{ |
119
|
194 |
|
if (!$this->propertyNsMap) { |
120
|
194 |
|
$this->propertyNsMap = new NamespacesMap(); |
121
|
194 |
|
$this->propertyNsMap->add('Flying\Struct\Property', 'default'); |
122
|
194 |
|
} |
123
|
194 |
|
return $this->propertyNsMap; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Get namespaces map for annotation classes |
128
|
|
|
* |
129
|
|
|
* @return NamespacesMap |
130
|
|
|
* @throws \InvalidArgumentException |
131
|
|
|
*/ |
132
|
194 |
|
public function getAnnotationNamespacesMap() |
133
|
|
|
{ |
134
|
194 |
|
if (!$this->annotationNsMap) { |
135
|
194 |
|
$this->annotationNsMap = new NamespacesMap(); |
136
|
194 |
|
$this->annotationNsMap->add('Flying\Struct\Annotation', 'default'); |
137
|
194 |
|
} |
138
|
194 |
|
return $this->annotationNsMap; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Get structures metadata manager |
143
|
|
|
* |
144
|
|
|
* @return MetadataManagerInterface |
145
|
|
|
*/ |
146
|
176 |
|
public function getMetadataManager() |
147
|
|
|
{ |
148
|
176 |
|
if (!$this->metadataManager) { |
149
|
175 |
|
$this->metadataManager = new MetadataManager(); |
150
|
175 |
|
} |
151
|
176 |
|
return $this->metadataManager; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Set structures metadata manager |
156
|
|
|
* |
157
|
|
|
* @param MetadataManagerInterface $manager |
158
|
|
|
* @return $this |
159
|
|
|
*/ |
160
|
1 |
|
public function setMetadataManager(MetadataManagerInterface $manager) |
161
|
|
|
{ |
162
|
1 |
|
$this->metadataManager = $manager; |
163
|
1 |
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Get structures metadata parser |
168
|
|
|
* |
169
|
|
|
* @return MetadataParserInterface |
170
|
|
|
*/ |
171
|
182 |
|
public function getMetadataParser() |
172
|
|
|
{ |
173
|
182 |
|
if (!$this->metadataParser) { |
174
|
182 |
|
$this->metadataParser = new AnnotationParser(); |
175
|
182 |
|
} |
176
|
182 |
|
return $this->metadataParser; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Set structures metadata parser |
181
|
|
|
* |
182
|
|
|
* @param MetadataParserInterface $parser |
183
|
|
|
* @return $this |
184
|
|
|
*/ |
185
|
|
|
public function setMetadataParser(MetadataParserInterface $parser) |
186
|
|
|
{ |
187
|
|
|
$this->metadataParser = $parser; |
188
|
|
|
return $this; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Get storage container |
193
|
|
|
* |
194
|
|
|
* @return StorageInterface |
195
|
|
|
*/ |
196
|
78 |
|
public function getStorage() |
197
|
|
|
{ |
198
|
78 |
|
if (!$this->storage) { |
199
|
77 |
|
$this->storage = new Storage(); |
200
|
77 |
|
} |
201
|
78 |
|
return $this->storage; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Set storage container |
206
|
|
|
* |
207
|
|
|
* @param StorageInterface $storage |
208
|
|
|
* @return $this |
209
|
|
|
*/ |
210
|
1 |
|
public function setStorage(StorageInterface $storage) |
211
|
|
|
{ |
212
|
1 |
|
$this->storage = $storage; |
213
|
1 |
|
return $this; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Get backend for structures storage |
218
|
|
|
* |
219
|
|
|
* @return BackendInterface |
220
|
|
|
*/ |
221
|
81 |
|
public function getStorageBackend() |
222
|
|
|
{ |
223
|
81 |
|
if (!$this->storageBackend) { |
224
|
81 |
|
$this->storageBackend = new ArrayBackend(); |
225
|
81 |
|
} |
226
|
81 |
|
return $this->storageBackend; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Set backend for structures storage |
231
|
|
|
* |
232
|
|
|
* @param BackendInterface $backend |
233
|
|
|
* @return $this |
234
|
|
|
*/ |
235
|
|
|
public function setStorageBackend(BackendInterface $backend) |
236
|
|
|
{ |
237
|
|
|
$this->storageBackend = $backend; |
238
|
|
|
return $this; |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
|