19
19
20
20
namespace Doctrine \ODM \MongoDB ;
21
21
22
+ use Doctrine \Common \EventManager ;
23
+ use Doctrine \Common \Persistence \ObjectManager ;
24
+ use Doctrine \MongoDB \Connection ;
25
+ use Doctrine \ODM \MongoDB \Hydrator \HydratorFactory ;
22
26
use Doctrine \ODM \MongoDB \Mapping \ClassMetadata ;
23
27
use Doctrine \ODM \MongoDB \Mapping \ClassMetadataFactory ;
24
- use Doctrine \ODM \MongoDB \Mapping \Driver \PHPDriver ;
25
- use Doctrine \MongoDB \Connection ;
26
- use Doctrine \ODM \MongoDB \PersistentCollection ;
27
28
use Doctrine \ODM \MongoDB \Proxy \ProxyFactory ;
28
- use Doctrine \Common \Collections \ArrayCollection ;
29
- use Doctrine \Common \EventManager ;
30
- use Doctrine \ODM \MongoDB \Hydrator \HydratorFactory ;
31
- use Doctrine \Common \Persistence \ObjectManager ;
32
29
use Doctrine \ODM \MongoDB \Query \FilterCollection ;
33
30
34
31
/**
@@ -84,7 +81,7 @@ class DocumentManager implements ObjectManager
84
81
/**
85
82
* The event manager that is the central point of the event system.
86
83
*
87
- * @var Doctrine\Common\EventManager
84
+ * @var \ Doctrine\Common\EventManager
88
85
*/
89
86
private $ eventManager ;
90
87
@@ -98,7 +95,7 @@ class DocumentManager implements ObjectManager
98
95
/**
99
96
* SchemaManager instance
100
97
*
101
- * @var Doctrine\ODM\MongoDB\ SchemaManager
98
+ * @var SchemaManager
102
99
*/
103
100
private $ schemaManager ;
104
101
@@ -130,7 +127,6 @@ class DocumentManager implements ObjectManager
130
127
*/
131
128
private $ cmd ;
132
129
133
-
134
130
/**
135
131
* Collection of query filters.
136
132
*
@@ -146,8 +142,7 @@ class DocumentManager implements ObjectManager
146
142
* @param Configuration|null $config
147
143
* @param \Doctrine\Common\EventManager|null $eventManager
148
144
*/
149
- protected function __construct (Connection $ conn = null , Configuration $ config = null , EventManager $ eventManager = null )
150
- {
145
+ protected function __construct (Connection $ conn = null , Configuration $ config = null , EventManager $ eventManager = null ) {
151
146
$ this ->config = $ config ?: new Configuration ();
152
147
$ this ->eventManager = $ eventManager ?: new EventManager ();
153
148
$ this ->cmd = $ this ->config ->getMongoCmd ();
@@ -164,21 +159,21 @@ protected function __construct(Connection $conn = null, Configuration $config =
164
159
$ hydratorDir = $ this ->config ->getHydratorDir ();
165
160
$ hydratorNs = $ this ->config ->getHydratorNamespace ();
166
161
$ this ->hydratorFactory = new HydratorFactory (
167
- $ this ,
168
- $ this ->eventManager ,
169
- $ hydratorDir ,
170
- $ hydratorNs ,
171
- $ this ->config ->getAutoGenerateHydratorClasses (),
172
- $ this ->config ->getMongoCmd ()
162
+ $ this ,
163
+ $ this ->eventManager ,
164
+ $ hydratorDir ,
165
+ $ hydratorNs ,
166
+ $ this ->config ->getAutoGenerateHydratorClasses (),
167
+ $ this ->config ->getMongoCmd ()
173
168
);
174
169
175
170
$ this ->unitOfWork = new UnitOfWork ($ this , $ this ->eventManager , $ this ->hydratorFactory , $ this ->cmd );
176
171
$ this ->hydratorFactory ->setUnitOfWork ($ this ->unitOfWork );
177
172
$ this ->schemaManager = new SchemaManager ($ this , $ this ->metadataFactory );
178
173
$ this ->proxyFactory = new ProxyFactory ($ this ,
179
- $ this ->config ->getProxyDir (),
180
- $ this ->config ->getProxyNamespace (),
181
- $ this ->config ->getAutoGenerateProxyClasses ()
174
+ $ this ->config ->getProxyDir (),
175
+ $ this ->config ->getProxyNamespace (),
176
+ $ this ->config ->getAutoGenerateProxyClasses ()
182
177
);
183
178
}
184
179
@@ -325,6 +320,7 @@ public function getDocumentDatabases()
325
320
* Returns the MongoCollection instance for a class.
326
321
*
327
322
* @param string $className The class name.
323
+ * @throws MongoDBException When the $className param is not mapped to a collection
328
324
* @return \Doctrine\MongoDB\Collection
329
325
*/
330
326
public function getDocumentCollection ($ className )
@@ -382,10 +378,11 @@ public function createQueryBuilder($documentName = null)
382
378
* this DocumentManager as NEW. Do not pass detached documents to the persist operation.
383
379
*
384
380
* @param object $document The instance to make managed and persistent.
381
+ * @throws \InvalidArgumentException When the given $document param is not an object
385
382
*/
386
383
public function persist ($ document )
387
384
{
388
- if (! is_object ($ document )) {
385
+ if ( ! is_object ($ document )) {
389
386
throw new \InvalidArgumentException (gettype ($ document ));
390
387
}
391
388
$ this ->errorIfClosed ();
@@ -399,10 +396,11 @@ public function persist($document)
399
396
* or as a result of the flush operation.
400
397
*
401
398
* @param object $document The document instance to remove.
399
+ * @throws \InvalidArgumentException when the $document param is not an object
402
400
*/
403
401
public function remove ($ document )
404
402
{
405
- if (! is_object ($ document )) {
403
+ if ( ! is_object ($ document )) {
406
404
throw new \InvalidArgumentException (gettype ($ document ));
407
405
}
408
406
$ this ->errorIfClosed ();
@@ -414,10 +412,11 @@ public function remove($document)
414
412
* overriding any local changes that have not yet been persisted.
415
413
*
416
414
* @param object $document The document to refresh.
415
+ * @throws \InvalidArgumentException When the given $document param is not an object
417
416
*/
418
417
public function refresh ($ document )
419
418
{
420
- if (! is_object ($ document )) {
419
+ if ( ! is_object ($ document )) {
421
420
throw new \InvalidArgumentException (gettype ($ document ));
422
421
}
423
422
$ this ->errorIfClosed ();
@@ -432,10 +431,11 @@ public function refresh($document)
432
431
* reference it.
433
432
*
434
433
* @param object $document The document to detach.
434
+ * @throws \InvalidArgumentException when the $document param is not an object
435
435
*/
436
436
public function detach ($ document )
437
437
{
438
- if (! is_object ($ document )) {
438
+ if ( ! is_object ($ document )) {
439
439
throw new \InvalidArgumentException (gettype ($ document ));
440
440
}
441
441
$ this ->unitOfWork ->detach ($ document );
@@ -447,11 +447,13 @@ public function detach($document)
447
447
* The document passed to merge will not become associated/managed with this DocumentManager.
448
448
*
449
449
* @param object $document The detached document to merge into the persistence context.
450
+ * @throws LockException
451
+ * @throws \InvalidArgumentException if the $document param is not an object
450
452
* @return object The managed copy of the document.
451
453
*/
452
454
public function merge ($ document )
453
455
{
454
- if (! is_object ($ document )) {
456
+ if ( ! is_object ($ document )) {
455
457
throw new \InvalidArgumentException (gettype ($ document ));
456
458
}
457
459
$ this ->errorIfClosed ();
@@ -464,12 +466,11 @@ public function merge($document)
464
466
* @param object $document
465
467
* @param int $lockMode
466
468
* @param int $lockVersion
467
- * @throws LockException
468
- * @throws LockException
469
+ * @throws \InvalidArgumentException
469
470
*/
470
471
public function lock ($ document , $ lockMode , $ lockVersion = null )
471
472
{
472
- if (! is_object ($ document )) {
473
+ if ( ! is_object ($ document )) {
473
474
throw new \InvalidArgumentException (gettype ($ document ));
474
475
}
475
476
$ this ->unitOfWork ->lock ($ document , $ lockMode , $ lockVersion );
@@ -479,10 +480,11 @@ public function lock($document, $lockMode, $lockVersion = null)
479
480
* Releases a lock on the given document.
480
481
*
481
482
* @param object $document
483
+ * @throws \InvalidArgumentException if the $document param is not an object
482
484
*/
483
485
public function unlock ($ document )
484
486
{
485
- if (! is_object ($ document )) {
487
+ if ( ! is_object ($ document )) {
486
488
throw new \InvalidArgumentException (gettype ($ document ));
487
489
}
488
490
$ this ->unitOfWork ->unlock ($ document );
@@ -521,10 +523,11 @@ public function getRepository($documentName)
521
523
*
522
524
* @param object $document
523
525
* @param array $options Array of options to be used with batchInsert(), update() and remove()
526
+ * @throws \InvalidArgumentException
524
527
*/
525
528
public function flush ($ document = null , array $ options = array ())
526
529
{
527
- if (null !== $ document && !is_object ($ document ) && !is_array ($ document )) {
530
+ if (null !== $ document && ! is_object ($ document ) && ! is_array ($ document )) {
528
531
throw new \InvalidArgumentException (gettype ($ document ));
529
532
}
530
533
$ this ->errorIfClosed ();
@@ -636,16 +639,17 @@ public function close()
636
639
* Determines whether a document instance is managed in this DocumentManager.
637
640
*
638
641
* @param object $document
642
+ * @throws \InvalidArgumentException When the $document param is not an object
639
643
* @return boolean TRUE if this DocumentManager currently manages the given document, FALSE otherwise.
640
644
*/
641
645
public function contains ($ document )
642
646
{
643
- if (! is_object ($ document )) {
647
+ if ( ! is_object ($ document )) {
644
648
throw new \InvalidArgumentException (gettype ($ document ));
645
649
}
646
650
return $ this ->unitOfWork ->isScheduledForInsert ($ document ) ||
647
- $ this ->unitOfWork ->isInIdentityMap ($ document ) &&
648
- ! $ this ->unitOfWork ->isScheduledForDelete ($ document );
651
+ $ this ->unitOfWork ->isInIdentityMap ($ document ) &&
652
+ ! $ this ->unitOfWork ->isScheduledForDelete ($ document );
649
653
}
650
654
651
655
/**
@@ -683,11 +687,12 @@ public function getClassNameFromDiscriminatorValue(array $mapping, $value)
683
687
* @param mixed $document A document object
684
688
* @param array $referenceMapping Mapping for the field the references the document
685
689
*
690
+ * @throws \InvalidArgumentException
686
691
* @return array A DBRef array
687
692
*/
688
693
public function createDBRef ($ document , array $ referenceMapping = null )
689
694
{
690
- if (! is_object ($ document )) {
695
+ if ( ! is_object ($ document )) {
691
696
throw new \InvalidArgumentException ('Cannot create a DBRef, the document is not an object ' );
692
697
}
693
698
$ className = get_class ($ document );
0 commit comments