1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Doctrine\ODM\MongoDB; |
21
|
|
|
|
22
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
23
|
|
|
use Doctrine\Common\Cache\Cache; |
24
|
|
|
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; |
25
|
|
|
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver; |
26
|
|
|
use Doctrine\ODM\MongoDB\Repository\DefaultRepositoryFactory; |
27
|
|
|
use Doctrine\ODM\MongoDB\Repository\RepositoryFactory; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Configuration class for the DocumentManager. When setting up your DocumentManager |
31
|
|
|
* you can optionally specify an instance of this class as the second argument. |
32
|
|
|
* If you do not pass a configuration object, a blank one will be created for you. |
33
|
|
|
* |
34
|
|
|
* <?php |
35
|
|
|
* |
36
|
|
|
* $config = new Configuration(); |
37
|
|
|
* $dm = DocumentManager::create(new Connection(), $config); |
38
|
|
|
* |
39
|
|
|
* @since 1.0 |
40
|
|
|
* @author Jonathan H. Wage <[email protected]> |
41
|
|
|
* @author Roman Borschel <[email protected]> |
42
|
|
|
*/ |
43
|
|
|
class Configuration extends \Doctrine\MongoDB\Configuration |
44
|
|
|
{ |
45
|
|
|
/** |
46
|
|
|
* Never autogenerate a proxy/hydrator and rely that it was generated by some |
47
|
|
|
* process before deployment. Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
48
|
|
|
* |
49
|
|
|
* @var integer |
50
|
|
|
*/ |
51
|
|
|
const AUTOGENERATE_NEVER = 0; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Always generates a new proxy/hydrator in every request. |
55
|
|
|
* |
56
|
|
|
* This is only sane during development. |
57
|
|
|
* Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
58
|
|
|
* |
59
|
|
|
* @var integer |
60
|
|
|
*/ |
61
|
|
|
const AUTOGENERATE_ALWAYS = 1; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Autogenerate the proxy/hydrator class when the file does not exist. |
65
|
|
|
* |
66
|
|
|
* This strategy causes a file exists call whenever any proxy/hydrator is used the |
67
|
|
|
* first time in a request. Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
68
|
|
|
* |
69
|
|
|
* @var integer |
70
|
|
|
*/ |
71
|
|
|
const AUTOGENERATE_FILE_NOT_EXISTS = 2; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Generate the proxy/hydrator classes using eval(). |
75
|
|
|
* |
76
|
|
|
* This strategy is only sane for development. |
77
|
|
|
* Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
78
|
|
|
* |
79
|
|
|
* @var integer |
80
|
|
|
*/ |
81
|
|
|
const AUTOGENERATE_EVAL = 3; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Adds a namespace under a certain alias. |
85
|
|
|
* |
86
|
|
|
* @param string $alias |
87
|
|
|
* @param string $namespace |
88
|
|
|
*/ |
89
|
|
|
public function addDocumentNamespace($alias, $namespace) |
90
|
|
|
{ |
91
|
|
|
$this->attributes['documentNamespaces'][$alias] = $namespace; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Resolves a registered namespace alias to the full namespace. |
96
|
|
|
* |
97
|
|
|
* @param string $documentNamespaceAlias |
98
|
|
|
* @return string |
99
|
|
|
* @throws MongoDBException |
100
|
|
|
*/ |
101
|
|
|
public function getDocumentNamespace($documentNamespaceAlias) |
102
|
|
|
{ |
103
|
|
|
if ( ! isset($this->attributes['documentNamespaces'][$documentNamespaceAlias])) { |
104
|
|
|
throw MongoDBException::unknownDocumentNamespace($documentNamespaceAlias); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return trim($this->attributes['documentNamespaces'][$documentNamespaceAlias], '\\'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Retrieves the list of registered document namespace aliases. |
112
|
|
|
* |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
|
|
public function getDocumentNamespaces() |
116
|
|
|
{ |
117
|
|
|
return $this->attributes['documentNamespaces']; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Set the document alias map |
122
|
|
|
* |
123
|
|
|
* @param array $documentNamespaces |
124
|
|
|
* @return void |
125
|
|
|
*/ |
126
|
|
|
public function setDocumentNamespaces(array $documentNamespaces) |
127
|
|
|
{ |
128
|
|
|
$this->attributes['documentNamespaces'] = $documentNamespaces; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Sets the cache driver implementation that is used for metadata caching. |
133
|
|
|
* |
134
|
|
|
* @param MappingDriver $driverImpl |
135
|
|
|
* @todo Force parameter to be a Closure to ensure lazy evaluation |
136
|
|
|
* (as soon as a metadata cache is in effect, the driver never needs to initialize). |
137
|
|
|
*/ |
138
|
937 |
|
public function setMetadataDriverImpl(MappingDriver $driverImpl) |
139
|
|
|
{ |
140
|
937 |
|
$this->attributes['metadataDriverImpl'] = $driverImpl; |
141
|
937 |
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Add a new default annotation driver with a correctly configured annotation reader. |
145
|
|
|
* |
146
|
|
|
* @param array $paths |
147
|
|
|
* @return Mapping\Driver\AnnotationDriver |
148
|
|
|
*/ |
149
|
|
|
public function newDefaultAnnotationDriver($paths = array()) |
150
|
|
|
{ |
151
|
|
|
$reader = new AnnotationReader(); |
152
|
|
|
|
153
|
|
|
return new AnnotationDriver($reader, (array)$paths); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Gets the cache driver implementation that is used for the mapping metadata. |
158
|
|
|
* |
159
|
|
|
* @return MappingDriver |
160
|
|
|
*/ |
161
|
754 |
|
public function getMetadataDriverImpl() |
162
|
|
|
{ |
163
|
754 |
|
return isset($this->attributes['metadataDriverImpl']) ? |
164
|
754 |
|
$this->attributes['metadataDriverImpl'] : null; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Gets the cache driver implementation that is used for metadata caching. |
169
|
|
|
* |
170
|
|
|
* @return \Doctrine\Common\Cache\Cache |
171
|
|
|
*/ |
172
|
921 |
|
public function getMetadataCacheImpl() |
173
|
|
|
{ |
174
|
921 |
|
return isset($this->attributes['metadataCacheImpl']) ? |
175
|
921 |
|
$this->attributes['metadataCacheImpl'] : null; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Sets the cache driver implementation that is used for metadata caching. |
180
|
|
|
* |
181
|
|
|
* @param \Doctrine\Common\Cache\Cache $cacheImpl |
182
|
|
|
*/ |
183
|
|
|
public function setMetadataCacheImpl(Cache $cacheImpl) |
184
|
|
|
{ |
185
|
|
|
$this->attributes['metadataCacheImpl'] = $cacheImpl; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Sets the directory where Doctrine generates any necessary proxy class files. |
190
|
|
|
* |
191
|
|
|
* @param string $dir |
192
|
|
|
*/ |
193
|
921 |
|
public function setProxyDir($dir) |
194
|
|
|
{ |
195
|
921 |
|
$this->attributes['proxyDir'] = $dir; |
196
|
921 |
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Gets the directory where Doctrine generates any necessary proxy class files. |
200
|
|
|
* |
201
|
|
|
* @return string |
202
|
|
|
*/ |
203
|
921 |
|
public function getProxyDir() |
204
|
|
|
{ |
205
|
921 |
|
return isset($this->attributes['proxyDir']) ? |
206
|
921 |
|
$this->attributes['proxyDir'] : null; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Gets a boolean flag that indicates whether proxy classes should always be regenerated |
211
|
|
|
* during each script execution. |
212
|
|
|
* |
213
|
|
|
* @return boolean|integer |
214
|
|
|
*/ |
215
|
921 |
|
public function getAutoGenerateProxyClasses() |
216
|
|
|
{ |
217
|
921 |
|
return isset($this->attributes['autoGenerateProxyClasses']) ? |
218
|
921 |
|
$this->attributes['autoGenerateProxyClasses'] : true; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Sets a boolean flag that indicates whether proxy classes should always be regenerated |
223
|
|
|
* during each script execution. |
224
|
|
|
* |
225
|
|
|
* @param boolean|int $bool Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory |
226
|
|
|
*/ |
227
|
|
|
public function setAutoGenerateProxyClasses($bool) |
228
|
|
|
{ |
229
|
|
|
$this->attributes['autoGenerateProxyClasses'] = $bool; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Gets the namespace where proxy classes reside. |
234
|
|
|
* |
235
|
|
|
* @return string |
236
|
|
|
*/ |
237
|
921 |
|
public function getProxyNamespace() |
238
|
|
|
{ |
239
|
921 |
|
return isset($this->attributes['proxyNamespace']) ? |
240
|
921 |
|
$this->attributes['proxyNamespace'] : null; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Sets the namespace where proxy classes reside. |
245
|
|
|
* |
246
|
|
|
* @param string $ns |
247
|
|
|
*/ |
248
|
921 |
|
public function setProxyNamespace($ns) |
249
|
|
|
{ |
250
|
921 |
|
$this->attributes['proxyNamespace'] = $ns; |
251
|
921 |
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Sets the directory where Doctrine generates hydrator class files. |
255
|
|
|
* |
256
|
|
|
* @param string $dir |
257
|
|
|
*/ |
258
|
921 |
|
public function setHydratorDir($dir) |
259
|
|
|
{ |
260
|
921 |
|
$this->attributes['hydratorDir'] = $dir; |
261
|
921 |
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Gets the directory where Doctrine generates hydrator class files. |
265
|
|
|
* |
266
|
|
|
* @return string |
267
|
|
|
*/ |
268
|
921 |
|
public function getHydratorDir() |
269
|
|
|
{ |
270
|
921 |
|
return isset($this->attributes['hydratorDir']) ? |
271
|
921 |
|
$this->attributes['hydratorDir'] : null; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* Gets a boolean flag that indicates whether hydrator classes should always be regenerated |
276
|
|
|
* during each script execution. |
277
|
|
|
* |
278
|
|
|
* @return boolean|integer Possible values are defined constants |
279
|
|
|
*/ |
280
|
921 |
|
public function getAutoGenerateHydratorClasses() |
281
|
|
|
{ |
282
|
921 |
|
return isset($this->attributes['autoGenerateHydratorClasses']) ? |
283
|
921 |
|
$this->attributes['autoGenerateHydratorClasses'] : true; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Sets a boolean flag that indicates whether hydrator classes should always be regenerated |
288
|
|
|
* during each script execution. |
289
|
|
|
* |
290
|
|
|
* @param boolean|integer $bool |
291
|
|
|
*/ |
292
|
|
|
public function setAutoGenerateHydratorClasses($bool) |
293
|
|
|
{ |
294
|
|
|
$this->attributes['autoGenerateHydratorClasses'] = $bool; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* Gets the namespace where hydrator classes reside. |
299
|
|
|
* |
300
|
|
|
* @return string |
301
|
|
|
*/ |
302
|
921 |
|
public function getHydratorNamespace() |
303
|
|
|
{ |
304
|
921 |
|
return isset($this->attributes['hydratorNamespace']) ? |
305
|
921 |
|
$this->attributes['hydratorNamespace'] : null; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Sets the namespace where hydrator classes reside. |
310
|
|
|
* |
311
|
|
|
* @param string $ns |
312
|
|
|
*/ |
313
|
921 |
|
public function setHydratorNamespace($ns) |
314
|
|
|
{ |
315
|
921 |
|
$this->attributes['hydratorNamespace'] = $ns; |
316
|
921 |
|
} |
317
|
|
|
|
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* Sets the default DB to use for all Documents that do not specify |
321
|
|
|
* a database. |
322
|
|
|
* |
323
|
|
|
* @param string $defaultDB |
324
|
|
|
*/ |
325
|
921 |
|
public function setDefaultDB($defaultDB) |
326
|
|
|
{ |
327
|
921 |
|
$this->attributes['defaultDB'] = $defaultDB; |
328
|
921 |
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Gets the default DB to use for all Documents that do not specify a database. |
332
|
|
|
* |
333
|
|
|
* @return string $defaultDB |
334
|
|
|
*/ |
335
|
676 |
|
public function getDefaultDB() |
336
|
|
|
{ |
337
|
676 |
|
return isset($this->attributes['defaultDB']) ? |
338
|
676 |
|
$this->attributes['defaultDB'] : null; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* Set the class metadata factory class name. |
343
|
|
|
* |
344
|
|
|
* @param string $cmfName |
345
|
|
|
*/ |
346
|
|
|
public function setClassMetadataFactoryName($cmfName) |
347
|
|
|
{ |
348
|
|
|
$this->attributes['classMetadataFactoryName'] = $cmfName; |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* Gets the class metadata factory class name. |
353
|
|
|
* |
354
|
|
|
* @return string |
355
|
|
|
*/ |
356
|
921 |
|
public function getClassMetadataFactoryName() |
357
|
|
|
{ |
358
|
921 |
|
if ( ! isset($this->attributes['classMetadataFactoryName'])) { |
359
|
921 |
|
$this->attributes['classMetadataFactoryName'] = 'Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory'; |
360
|
921 |
|
} |
361
|
921 |
|
return $this->attributes['classMetadataFactoryName']; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* Gets array of default commit options. |
366
|
|
|
* |
367
|
|
|
* @return array |
368
|
|
|
*/ |
369
|
554 |
|
public function getDefaultCommitOptions() |
370
|
|
|
{ |
371
|
554 |
|
if (isset($this->attributes['defaultCommitOptions'])) { |
372
|
|
|
return $this->attributes['defaultCommitOptions']; |
373
|
|
|
} |
374
|
|
|
|
375
|
554 |
|
return array('w' => 1); |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* Sets array of default commit options. |
380
|
|
|
* |
381
|
|
|
* @param boolean $defaultCommitOptions |
382
|
|
|
*/ |
383
|
|
|
public function setDefaultCommitOptions($defaultCommitOptions) |
384
|
|
|
{ |
385
|
|
|
$this->attributes['defaultCommitOptions'] = $defaultCommitOptions; |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* Add a filter to the list of possible filters. |
390
|
|
|
* |
391
|
|
|
* @param string $name The name of the filter. |
392
|
|
|
* @param string $className The class name of the filter. |
393
|
|
|
* @param array $parameters The parameters for the filter. |
394
|
|
|
*/ |
395
|
921 |
|
public function addFilter($name, $className, array $parameters = array()) |
396
|
|
|
{ |
397
|
921 |
|
$this->attributes['filters'][$name] = array( |
398
|
921 |
|
'class' => $className, |
399
|
|
|
'parameters' => $parameters |
400
|
921 |
|
); |
401
|
921 |
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* Gets the class name for a given filter name. |
405
|
|
|
* |
406
|
|
|
* @param string $name The name of the filter. |
407
|
|
|
* |
408
|
|
|
* @return string|null The filter class name, or null if it is undefined |
409
|
|
|
*/ |
410
|
22 |
|
public function getFilterClassName($name) |
411
|
|
|
{ |
412
|
22 |
|
return isset($this->attributes['filters'][$name]) |
413
|
22 |
|
? $this->attributes['filters'][$name]['class'] |
414
|
22 |
|
: null; |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* Gets the parameters for a given filter name. |
419
|
|
|
* |
420
|
|
|
* @param string $name The name of the filter. |
421
|
|
|
* |
422
|
|
|
* @return array|null The filter parameters, or null if it is undefined |
423
|
|
|
*/ |
424
|
21 |
|
public function getFilterParameters($name) |
425
|
|
|
{ |
426
|
21 |
|
return isset($this->attributes['filters'][$name]) |
427
|
21 |
|
? $this->attributes['filters'][$name]['parameters'] |
428
|
21 |
|
: null; |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* Sets default repository class. |
433
|
|
|
* |
434
|
|
|
* @param string $className |
435
|
|
|
* |
436
|
|
|
* @return void |
437
|
|
|
* |
438
|
|
|
* @throws MongoDBException If not is a ObjectRepository |
439
|
|
|
*/ |
440
|
|
|
public function setDefaultRepositoryClassName($className) |
441
|
|
|
{ |
442
|
|
|
$reflectionClass = new \ReflectionClass($className); |
443
|
|
|
|
444
|
|
|
if ( ! $reflectionClass->implementsInterface('Doctrine\Common\Persistence\ObjectRepository')) { |
445
|
|
|
throw MongoDBException::invalidDocumentRepository($className); |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
$this->attributes['defaultRepositoryClassName'] = $className; |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
/** |
452
|
|
|
* Get default repository class. |
453
|
|
|
* |
454
|
|
|
* @return string |
455
|
|
|
*/ |
456
|
320 |
|
public function getDefaultRepositoryClassName() |
457
|
|
|
{ |
458
|
320 |
|
return isset($this->attributes['defaultRepositoryClassName']) |
459
|
320 |
|
? $this->attributes['defaultRepositoryClassName'] |
460
|
320 |
|
: 'Doctrine\ODM\MongoDB\DocumentRepository'; |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* Set the document repository factory. |
465
|
|
|
* |
466
|
|
|
* @param RepositoryFactory $repositoryFactory |
467
|
|
|
*/ |
468
|
|
|
public function setRepositoryFactory(RepositoryFactory $repositoryFactory) |
469
|
|
|
{ |
470
|
|
|
$this->attributes['repositoryFactory'] = $repositoryFactory; |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
/** |
474
|
|
|
* Get the document repository factory. |
475
|
|
|
* |
476
|
|
|
* @return RepositoryFactory |
477
|
|
|
*/ |
478
|
921 |
|
public function getRepositoryFactory() |
479
|
|
|
{ |
480
|
921 |
|
return isset($this->attributes['repositoryFactory']) |
481
|
921 |
|
? $this->attributes['repositoryFactory'] |
482
|
921 |
|
: new DefaultRepositoryFactory(); |
483
|
|
|
} |
484
|
|
|
} |
485
|
|
|
|