forked from doctrine/mongodb-odm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfiguration.php
370 lines (336 loc) · 10.5 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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?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 MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ODM\MongoDB;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
/**
* Configuration class for the DocumentManager. When setting up your DocumentManager
* you can optionally specify an instance of this class as the second argument.
* If you do not pass a configuration object, a blank one will be created for you.
*
* <?php
*
* $config = new Configuration();
* $dm = DocumentManager::create(new Connection(), $config);
*
* @since 1.0
* @author Jonathan H. Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class Configuration extends \Doctrine\MongoDB\Configuration
{
/**
* 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 MongoDBException
*/
public function getDocumentNamespace($documentNamespaceAlias)
{
if ( ! isset($this->attributes['documentNamespaces'][$documentNamespaceAlias])) {
throw MongoDBException::unknownDocumentNamespace($documentNamespaceAlias);
}
return trim($this->attributes['documentNamespaces'][$documentNamespaceAlias], '\\');
}
/**
* Retrieves the list of registered document namespace aliases.
*
* @return array
*/
public function getDocumentNamespaces()
{
return $this->attributes['documentNamespaces'];
}
/**
* Set the document alias map
*
* @param array $documentNamespaces
* @return void
*/
public function setDocumentNamespaces(array $documentNamespaces)
{
$this->attributes['documentNamespaces'] = $documentNamespaces;
}
/**
* Sets the cache driver implementation that is used for metadata caching.
*
* @param MappingDriver $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(MappingDriver $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 AnnotationReader();
return new AnnotationDriver($reader, (array)$paths);
}
/**
* Gets the cache driver implementation that is used for the mapping metadata.
*
* @return MappingDriver
*/
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()
{
return isset($this->attributes['proxyDir']) ?
$this->attributes['proxyDir'] : null;
}
/**
* Gets a boolean flag that indicates whether proxy classes should always be regenerated
* during each script execution.
*
* @return boolean
*/
public function getAutoGenerateProxyClasses()
{
return isset($this->attributes['autoGenerateProxyClasses']) ?
$this->attributes['autoGenerateProxyClasses'] : true;
}
/**
* Sets a boolean flag that indicates whether proxy classes should always be regenerated
* during each script execution.
*
* @param boolean $bool
*/
public function setAutoGenerateProxyClasses($bool)
{
$this->attributes['autoGenerateProxyClasses'] = $bool;
}
/**
* Gets the namespace where proxy classes reside.
*
* @return string
*/
public function getProxyNamespace()
{
return isset($this->attributes['proxyNamespace']) ?
$this->attributes['proxyNamespace'] : null;
}
/**
* Sets the namespace where proxy classes reside.
*
* @param string $ns
*/
public function setProxyNamespace($ns)
{
$this->attributes['proxyNamespace'] = $ns;
}
/**
* Sets the directory where Doctrine generates hydrator class files.
*
* @param string $dir
*/
public function setHydratorDir($dir)
{
$this->attributes['hydratorDir'] = $dir;
}
/**
* Gets the directory where Doctrine generates hydrator class files.
*
* @return string
*/
public function getHydratorDir()
{
return isset($this->attributes['hydratorDir']) ?
$this->attributes['hydratorDir'] : null;
}
/**
* Gets a boolean flag that indicates whether hydrator classes should always be regenerated
* during each script execution.
*
* @return boolean
*/
public function getAutoGenerateHydratorClasses()
{
return isset($this->attributes['autoGenerateHydratorClasses']) ?
$this->attributes['autoGenerateHydratorClasses'] : true;
}
/**
* Sets a boolean flag that indicates whether hydrator classes should always be regenerated
* during each script execution.
*
* @param boolean $bool
*/
public function setAutoGenerateHydratorClasses($bool)
{
$this->attributes['autoGenerateHydratorClasses'] = $bool;
}
/**
* Gets the namespace where hydrator classes reside.
*
* @return string
*/
public function getHydratorNamespace()
{
return isset($this->attributes['hydratorNamespace']) ?
$this->attributes['hydratorNamespace'] : null;
}
/**
* Sets the namespace where hydrator classes reside.
*
* @param string $ns
*/
public function setHydratorNamespace($ns)
{
$this->attributes['hydratorNamespace'] = $ns;
}
/**
* Sets the default DB to use for all Documents that do not specify
* a database.
*
* @param string $defaultDB
*/
public function setDefaultDB($defaultDB)
{
$this->attributes['defaultDB'] = $defaultDB;
}
/**
* Gets the default DB to use for all Documents that do not specify a database.
*
* @return string $defaultDB
*/
public function getDefaultDB()
{
return isset($this->attributes['defaultDB']) ?
$this->attributes['defaultDB'] : null;
}
/**
* Set the class metadata factory class name.
*
* @param string $cmfName
*/
public function setClassMetadataFactoryName($cmfName)
{
$this->_attributes['classMetadataFactoryName'] = $cmfName;
}
/**
* Gets the class metadata factory class name.
*
* @return string
*/
public function getClassMetadataFactoryName()
{
if ( ! isset($this->_attributes['classMetadataFactoryName'])) {
$this->_attributes['classMetadataFactoryName'] = 'Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory';
}
return $this->_attributes['classMetadataFactoryName'];
}
/**
* Gets array of default commit options.
*
* @return boolean
*/
public function getDefaultCommitOptions()
{
return isset($this->attributes['defaultCommitOptions']) ?
$this->attributes['defaultCommitOptions'] : array('safe' => true);
}
/**
* Sets array of default commit options.
*
* @param boolean $defaultCommitOptions
*/
public function setDefaultCommitOptions($defaultCommitOptions)
{
$this->attributes['defaultCommitOptions'] = $defaultCommitOptions;
}
/**
* Add a filter to the list of possible filters.
*
* @param string $name The name of the filter.
* @param string $className The class name of the filter.
*/
public function addFilter($name, $className)
{
$this->attributes['filters'][$name] = $className;
}
/**
* Gets the class name for a given filter name.
*
* @param string $name The name of the filter.
*
* @return string The class name of the filter, or null of it is not
* defined.
*/
public function getFilterClassName($name)
{
return isset($this->attributes['filters'][$name])
? $this->attributes['filters'][$name]
: null;
}
}