1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\ODM\CouchDB; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Cache\Cache; |
6
|
|
|
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; |
7
|
|
|
|
8
|
|
|
use Doctrine\CouchDB\HTTP\Client; |
9
|
|
|
use Doctrine\CouchDB\HTTP\SocketClient; |
10
|
|
|
use Doctrine\CouchDB\HTTP\LoggingClient; |
11
|
|
|
|
12
|
|
|
use Doctrine\ODM\CouchDB\Mapping\MetadataResolver\MetadataResolver; |
13
|
|
|
use Doctrine\ODM\CouchDB\Mapping\MetadataResolver\DoctrineResolver; |
14
|
|
|
use Doctrine\ODM\CouchDB\Migrations\DocumentMigration; |
15
|
|
|
use Doctrine\ODM\CouchDB\Proxy\ProxyFactory; |
16
|
|
|
use ProxyManager\Configuration as ProxyManagerConfiguration; |
17
|
|
|
use ProxyManager\Factory\LazyLoadingGhostFactory; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Configuration class |
21
|
|
|
* |
22
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL |
23
|
|
|
* @link www.doctrine-project.com |
24
|
|
|
* @since 1.0 |
25
|
|
|
* @author Benjamin Eberlei <[email protected]> |
26
|
|
|
* @author Lukas Kahwe Smith <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class Configuration |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Array of attributes for this configuration instance. |
32
|
|
|
* |
33
|
|
|
* @var array $attributes |
34
|
|
|
*/ |
35
|
|
|
private $attributes = array( |
36
|
|
|
'designDocuments' => array( |
37
|
|
|
'doctrine_associations' => array( |
38
|
|
|
'className' => 'Doctrine\ODM\CouchDB\View\DoctrineAssociations', |
39
|
|
|
'options' => array(), |
40
|
|
|
), |
41
|
|
|
'doctrine_repositories' => array( |
42
|
|
|
'className' => 'Doctrine\ODM\CouchDB\View\DoctrineRepository', |
43
|
|
|
'options' => array(), |
44
|
|
|
), |
45
|
|
|
), |
46
|
|
|
'writeDoctrineMetadata' => true, |
47
|
|
|
'validateDoctrineMetadata' => true, |
48
|
|
|
'UUIDGenerationBufferSize' => 20, |
49
|
|
|
'proxyNamespace' => 'MyCouchDBProxyNS', |
50
|
|
|
'allOrNothingFlush' => true, |
51
|
|
|
'luceneHandlerName' => false, |
52
|
|
|
'metadataResolver' => null, |
53
|
|
|
'autoGenerateProxyClasses' => false, |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
/** @var ProxyManagerConfiguration|null */ |
57
|
|
|
private $proxyManagerConfiguration; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Sets the default UUID Generator buffer size |
61
|
|
|
* |
62
|
|
|
* @param integer $UUIDGenerationBufferSize |
63
|
|
|
*/ |
64
|
|
|
public function setUUIDGenerationBufferSize($UUIDGenerationBufferSize) |
65
|
|
|
{ |
66
|
|
|
$this->attributes['UUIDGenerationBufferSize'] = $UUIDGenerationBufferSize; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Gets the default UUID Generator buffer size |
71
|
|
|
* |
72
|
|
|
* @return integer |
73
|
|
|
*/ |
74
|
|
|
public function getUUIDGenerationBufferSize() |
75
|
|
|
{ |
76
|
|
|
return $this->attributes['UUIDGenerationBufferSize']; |
77
|
|
|
} |
78
|
|
|
/** |
79
|
|
|
* Sets if all CouchDB document metadata should be validated on read |
80
|
|
|
* |
81
|
|
|
* @param boolean $validateDoctrineMetadata |
82
|
|
|
*/ |
83
|
|
|
public function setValidateDoctrineMetadata($validateDoctrineMetadata) |
84
|
|
|
{ |
85
|
|
|
$this->attributes['validateDoctrineMetadata'] = $validateDoctrineMetadata; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Gets if all CouchDB document metadata should be validated on read |
90
|
|
|
* |
91
|
|
|
* @return boolean |
92
|
|
|
*/ |
93
|
|
|
public function getValidateDoctrineMetadata() |
94
|
|
|
{ |
95
|
|
|
return $this->attributes['validateDoctrineMetadata']; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Adds a namespace under a certain alias. |
100
|
|
|
* |
101
|
|
|
* @param string $alias |
102
|
|
|
* @param string $namespace |
103
|
|
|
*/ |
104
|
|
|
public function addDocumentNamespace($alias, $namespace) |
105
|
|
|
{ |
106
|
|
|
$this->attributes['documentNamespaces'][$alias] = $namespace; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Resolves a registered namespace alias to the full namespace. |
111
|
|
|
* |
112
|
|
|
* @param string $documentNamespaceAlias |
113
|
|
|
* @return string |
114
|
|
|
* @throws CouchDBException |
115
|
|
|
*/ |
116
|
|
|
public function getDocumentNamespace($documentNamespaceAlias) |
117
|
|
|
{ |
118
|
|
|
if ( ! isset($this->attributes['documentNamespaces'][$documentNamespaceAlias])) { |
119
|
|
|
throw CouchDBException::unknownDocumentNamespace($documentNamespaceAlias); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
return trim($this->attributes['documentNamespaces'][$documentNamespaceAlias], '\\'); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Set the document alias map |
127
|
|
|
* |
128
|
|
|
* @param array $documentNamespaces |
129
|
|
|
* @return void |
130
|
|
|
*/ |
131
|
|
|
public function setDocumentNamespaces(array $documentNamespaces) |
132
|
|
|
{ |
133
|
|
|
$this->attributes['documentNamespaces'] = $documentNamespaces; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Sets the cache driver implementation that is used for metadata caching. |
138
|
|
|
* |
139
|
|
|
* @param MappingDriver $driverImpl |
140
|
|
|
* @todo Force parameter to be a Closure to ensure lazy evaluation |
141
|
|
|
* (as soon as a metadata cache is in effect, the driver never needs to initialize). |
142
|
|
|
*/ |
143
|
|
|
public function setMetadataDriverImpl(MappingDriver $driverImpl) |
144
|
|
|
{ |
145
|
|
|
$this->attributes['metadataDriverImpl'] = $driverImpl; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Add a new default annotation driver with a correctly configured annotation reader. |
150
|
|
|
* |
151
|
|
|
* @param array $paths |
152
|
|
|
* @return Mapping\Driver\AnnotationDriver |
153
|
|
|
*/ |
154
|
|
|
public function newDefaultAnnotationDriver($paths = array()) |
155
|
|
|
{ |
156
|
|
|
$reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader(); |
157
|
|
|
$reader->addNamespace('Doctrine\ODM\CouchDB\Mapping\Annotations'); |
158
|
|
|
|
159
|
|
|
return new \Doctrine\ODM\CouchDB\Mapping\Driver\AnnotationDriver($reader, (array) $paths); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function setMetadataResolverImpl(MetadataResolver $resolver) |
163
|
|
|
{ |
164
|
|
|
$this->attributes['metadataResolver'] = $resolver; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function getMetadataResolverImpl() |
168
|
|
|
{ |
169
|
|
|
if (!$this->attributes['metadataResolver']) { |
170
|
|
|
return new DoctrineResolver(); |
171
|
|
|
} |
172
|
|
|
return $this->attributes['metadataResolver']; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Gets the cache driver implementation that is used for the mapping metadata. |
177
|
|
|
* |
178
|
|
|
* @return MappingDriver |
179
|
|
|
*/ |
180
|
|
|
public function getMetadataDriverImpl() |
181
|
|
|
{ |
182
|
|
|
if (!isset($this->attributes['metadataDriverImpl'])) { |
183
|
|
|
$this->attributes['metadataDriverImpl'] = $this->newDefaultAnnotationDriver(); |
184
|
|
|
} |
185
|
|
|
return $this->attributes['metadataDriverImpl']; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Gets the cache driver implementation that is used for metadata caching. |
190
|
|
|
* |
191
|
|
|
* @return \Doctrine\Common\Cache\Cache |
192
|
|
|
*/ |
193
|
|
|
public function getMetadataCacheImpl() |
194
|
|
|
{ |
195
|
|
|
return isset($this->attributes['metadataCacheImpl']) ? |
196
|
|
|
$this->attributes['metadataCacheImpl'] : null; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Sets the cache driver implementation that is used for metadata caching. |
201
|
|
|
* |
202
|
|
|
* @param \Doctrine\Common\Cache\Cache $cacheImpl |
203
|
|
|
*/ |
204
|
|
|
public function setMetadataCacheImpl(Cache $cacheImpl) |
205
|
|
|
{ |
206
|
|
|
$this->attributes['metadataCacheImpl'] = $cacheImpl; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Sets the directory where Doctrine generates any necessary proxy class files. |
211
|
|
|
* |
212
|
|
|
* @param string $directory |
213
|
|
|
*/ |
214
|
|
|
public function setProxyDir($directory) |
215
|
|
|
{ |
216
|
|
|
$this->getProxyManagerConfiguration()->setProxiesTargetDir($directory); |
217
|
|
|
$this->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Sets the namespace for Doctrine proxy class files. |
222
|
|
|
* |
223
|
|
|
* @param string $namespace |
224
|
|
|
*/ |
225
|
|
|
public function setProxyNamespace($namespace) |
226
|
|
|
{ |
227
|
|
|
$this->attributes['proxyNamespace'] = $namespace; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Gets the namespace for Doctrine proxy class files. |
232
|
|
|
* |
233
|
|
|
* @return string |
234
|
|
|
*/ |
235
|
|
|
public function getProxyNamespace() |
236
|
|
|
{ |
237
|
|
|
return $this->attributes['proxyNamespace']; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
public function setAutoGenerateProxyClasses($bool) |
241
|
|
|
{ |
242
|
|
|
$this->attributes['autoGenerateProxyClasses'] = $bool; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
public function getAutoGenerateProxyClasses() |
246
|
|
|
{ |
247
|
|
|
return $this->attributes['autoGenerateProxyClasses']; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @param string $name |
252
|
|
|
* @param string $className |
253
|
|
|
* @param array $options |
254
|
|
|
*/ |
255
|
|
|
public function addDesignDocument($name, $className, $options) |
256
|
|
|
{ |
257
|
|
|
$this->attributes['designDocuments'][$name] = array( |
258
|
|
|
'className' => $className, |
259
|
|
|
'options' => $options, |
260
|
|
|
); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @return array |
265
|
|
|
*/ |
266
|
|
|
public function getDesignDocumentNames() |
267
|
|
|
{ |
268
|
|
|
return array_keys($this->attributes['designDocuments']); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @param string $name |
273
|
|
|
* @return array |
274
|
|
|
*/ |
275
|
|
|
public function getDesignDocument($name) |
276
|
|
|
{ |
277
|
|
|
if (isset($this->attributes['designDocuments'][$name])) { |
278
|
|
|
return $this->attributes['designDocuments'][$name]; |
279
|
|
|
} |
280
|
|
|
return null; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @param bool $allOrNothing |
285
|
|
|
*/ |
286
|
|
|
public function setAllOrNothingFlush($allOrNothing) |
287
|
|
|
{ |
288
|
|
|
$this->attributes['allOrNothingFlush'] = (bool)$allOrNothing; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @return bool |
293
|
|
|
*/ |
294
|
|
|
public function getAllOrNothingFlush() |
295
|
|
|
{ |
296
|
|
|
return $this->attributes['allOrNothingFlush']; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
public function setLuceneHandlerName($handlerName = '_fti') |
300
|
|
|
{ |
301
|
|
|
$this->attributes['luceneHandlerName'] = $handlerName; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
public function getLuceneHandlerName() |
305
|
|
|
{ |
306
|
|
|
if (!$this->attributes['luceneHandlerName']) { |
307
|
|
|
throw CouchDBException::luceneNotConfigured(); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
return $this->attributes['luceneHandlerName']; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* @return \Doctrine\ODM\CouchDB\Migrations\NullMigration; |
|
|
|
|
315
|
|
|
*/ |
316
|
|
|
public function getMigrations() |
317
|
|
|
{ |
318
|
|
|
if (!isset($this->attributes['migrations'])) { |
319
|
|
|
$this->attributes['migrations'] = new Migrations\NullMigration(); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
return $this->attributes['migrations']; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* @param DocumentMigration $migration |
327
|
|
|
*/ |
328
|
|
|
public function setMigrations(DocumentMigration $migration) |
329
|
|
|
{ |
330
|
|
|
$this->attributes['migrations'] = $migration; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
public function buildGhostObjectFactory() : LazyLoadingGhostFactory |
334
|
|
|
{ |
335
|
|
|
return new LazyLoadingGhostFactory(clone $this->getProxyManagerConfiguration()); |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
public function getProxyManagerConfiguration() : ProxyManagerConfiguration |
339
|
|
|
{ |
340
|
|
|
return $this->proxyManagerConfiguration |
341
|
|
|
?? $this->proxyManagerConfiguration = new ProxyManagerConfiguration(); |
342
|
|
|
} |
343
|
|
|
} |
344
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.