This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
/
Configuration.php
355 lines (320 loc) · 10 KB
/
Configuration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ODM\CouchDB;
use Doctrine\Common\Cache\Cache;
use Doctrine\ODM\CouchDB\HTTP\Client;
use Doctrine\ODM\CouchDB\Mapping\Driver\Driver;
use Doctrine\ODM\CouchDB\Mapping\MetadataResolver\MetadataResolver;
use Doctrine\ODM\CouchDB\Mapping\MetadataResolver\DoctrineResolver;
/**
* Configuration class
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 1.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
*/
class Configuration
{
/**
* Array of attributes for this configuration instance.
*
* @var array $attributes
*/
private $attributes = array(
'designDocuments' => array(
'doctrine_associations' => array(
'className' => 'Doctrine\ODM\CouchDB\View\DoctrineAssociations',
'options' => array(),
),
'doctrine_repositories' => array(
'className' => 'Doctrine\ODM\CouchDB\View\DoctrineRepository',
'options' => array(),
),
),
'writeDoctrineMetadata' => true,
'validateDoctrineMetadata' => true,
'UUIDGenerationBufferSize' => 20,
'proxyNamespace' => 'MyCouchDBProxyNS',
'allOrNothingFlush' => true,
'luceneHandlerName' => false,
'metadataResolver' => null,
);
/**
* Sets the default UUID Generator buffer size
*
* @param integer $UUIDGenerationBufferSize
*/
public function setUUIDGenerationBufferSize($UUIDGenerationBufferSize)
{
$this->attributes['UUIDGenerationBufferSize'] = $UUIDGenerationBufferSize;
}
/**
* Gets the default UUID Generator buffer size
*
* @return integer
*/
public function getUUIDGenerationBufferSize()
{
return $this->attributes['UUIDGenerationBufferSize'];
}
/**
* Sets if all CouchDB document metadata should be validated on read
*
* @param boolean $validateDoctrineMetadata
*/
public function setValidateDoctrineMetadata($validateDoctrineMetadata)
{
$this->attributes['validateDoctrineMetadata'] = $validateDoctrineMetadata;
}
/**
* Gets if all CouchDB document metadata should be validated on read
*
* @return boolean
*/
public function getValidateDoctrineMetadata()
{
return $this->attributes['validateDoctrineMetadata'];
}
/**
* Sets the HTTP client instance to use for the CouchDB communication
*
* @param Client $client
*/
public function setHttpClient(Client $client)
{
$this->attributes['httpclient'] = $client;
}
/**
* Gets the HTTP client instance to use for the CouchDB communication
*
* @return Client
*/
public function getHttpClient()
{
if (!isset($this->attributes['httpclient'])) {
$this->attributes['httpclient'] = new HTTP\SocketClient();
}
return $this->attributes['httpclient'];
}
/**
* Adds a namespace under a certain alias.
*
* @param string $alias
* @param string $namespace
*/
public function addDocumentNamespace($alias, $namespace)
{
$this->attributes['documentNamespaces'][$alias] = $namespace;
}
/**
* Resolves a registered namespace alias to the full namespace.
*
* @param string $documentNamespaceAlias
* @return string
* @throws CouchDBException
*/
public function getDocumentNamespace($documentNamespaceAlias)
{
if ( ! isset($this->attributes['documentNamespaces'][$documentNamespaceAlias])) {
throw CouchDBException::unknownDocumentNamespace($documentNamespaceAlias);
}
return trim($this->attributes['documentNamespaces'][$documentNamespaceAlias], '\\');
}
/**
* Set the document alias map
*
* @param array $documentAliasMap
* @return void
*/
public function setDocumentNamespaces(array $documentNamespaces)
{
$this->attributes['documentNamespaces'] = $documentNamespaces;
}
/**
* Sets the cache driver implementation that is used for metadata caching.
*
* @param Driver $driverImpl
* @todo Force parameter to be a Closure to ensure lazy evaluation
* (as soon as a metadata cache is in effect, the driver never needs to initialize).
*/
public function setMetadataDriverImpl(Driver $driverImpl)
{
$this->attributes['metadataDriverImpl'] = $driverImpl;
}
/**
* Add a new default annotation driver with a correctly configured annotation reader.
*
* @param array $paths
* @return Mapping\Driver\AnnotationDriver
*/
public function newDefaultAnnotationDriver($paths = array())
{
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reader->setDefaultAnnotationNamespace('Doctrine\ODM\CouchDB\Mapping\\');
return new \Doctrine\ODM\CouchDB\Mapping\Driver\AnnotationDriver($reader, (array) $paths);
}
public function setMetadataResolverImpl(MetadataResolver $resolver)
{
$this->attributes['metadataResolver'] = $resolver;
}
public function getMetadataResolverImpl()
{
if (!$this->attributes['metadataResolver']) {
return new DoctrineResolver();
}
return $this->attributes['metadataResolver'];
}
/**
* Gets the cache driver implementation that is used for the mapping metadata.
*
* @return Mapping\Driver\Driver
*/
public function getMetadataDriverImpl()
{
return isset($this->attributes['metadataDriverImpl']) ?
$this->attributes['metadataDriverImpl'] : null;
}
/**
* Gets the cache driver implementation that is used for metadata caching.
*
* @return \Doctrine\Common\Cache\Cache
*/
public function getMetadataCacheImpl()
{
return isset($this->attributes['metadataCacheImpl']) ?
$this->attributes['metadataCacheImpl'] : null;
}
/**
* Sets the cache driver implementation that is used for metadata caching.
*
* @param \Doctrine\Common\Cache\Cache $cacheImpl
*/
public function setMetadataCacheImpl(Cache $cacheImpl)
{
$this->attributes['metadataCacheImpl'] = $cacheImpl;
}
/**
* Sets the directory where Doctrine generates any necessary proxy class files.
*
* @param string $dir
*/
public function setProxyDir($dir)
{
$this->attributes['proxyDir'] = $dir;
}
/**
* Gets the directory where Doctrine generates any necessary proxy class files.
*
* @return string
*/
public function getProxyDir()
{
if (!isset($this->attributes['proxyDir'])) {
$this->attributes['proxyDir'] = \sys_get_temp_dir();
}
return $this->attributes['proxyDir'];
}
/**
* Sets the namespace for Doctrine proxy class files.
*
* @param string $namespace
*/
public function setProxyNamespace($namespace)
{
$this->attributes['proxyNamespace'] = $namespace;
}
/**
* Gets the namespace for Doctrine proxy class files.
*
* @return string
*/
public function getProxyNamespace()
{
return $this->attributes['proxyNamespace'];
}
/**
* Set the database name
*
* @param string $prefix The prefix for names of databases
*/
public function setDatabase($databaseName)
{
$this->attributes['databaseName'] = $databaseName;
}
/**
* Get the database name
*
*
* @return string
*/
public function getDatabase()
{
return isset($this->attributes['databaseName']) ?
$this->attributes['databaseName'] : null;
}
/**
* @param string $name
* @param string $className
*/
public function addDesignDocument($name, $className, $options)
{
$this->attributes['designDocuments'][$name] = array(
'className' => $className,
'options' => $options,
);
}
/**
* @param string $name
* @return string|null
*/
public function getDesignDocument($name)
{
if (isset($this->attributes['designDocuments'][$name])) {
return $this->attributes['designDocuments'][$name];
}
return null;
}
/**
* @param bool $allOrNothing
*/
public function setAllOrNothingFlush($allOrNothing)
{
$this->attributes['allOrNothingFlush'] = (bool)$allOrNothing;
}
/**
* @return bool
*/
public function getAllOrNothingFlush()
{
return $this->attributes['allOrNothingFlush'];
}
public function setLuceneHandlerName($handlerName = '_fti')
{
$this->attributes['luceneHandlerName'] = $handlerName;
}
public function getLuceneHandlerName()
{
if (!$this->attributes['luceneHandlerName']) {
throw CouchDBException::luceneNotConfigured();
}
return $this->attributes['luceneHandlerName'];
}
}