Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like UnitOfWork often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UnitOfWork, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 47 | class UnitOfWork implements PropertyChangedListener |
||
| 48 | { |
||
| 49 | /** |
||
| 50 | * A document is in MANAGED state when its persistence is managed by a DocumentManager. |
||
| 51 | */ |
||
| 52 | const STATE_MANAGED = 1; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * A document is new if it has just been instantiated (i.e. using the "new" operator) |
||
| 56 | * and is not (yet) managed by a DocumentManager. |
||
| 57 | */ |
||
| 58 | const STATE_NEW = 2; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * A detached document is an instance with a persistent identity that is not |
||
| 62 | * (or no longer) associated with a DocumentManager (and a UnitOfWork). |
||
| 63 | */ |
||
| 64 | const STATE_DETACHED = 3; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * A removed document instance is an instance with a persistent identity, |
||
| 68 | * associated with a DocumentManager, whose persistent state has been |
||
| 69 | * deleted (or is scheduled for deletion). |
||
| 70 | */ |
||
| 71 | const STATE_REMOVED = 4; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * The identity map holds references to all managed documents. |
||
| 75 | * |
||
| 76 | * Documents are grouped by their class name, and then indexed by the |
||
| 77 | * serialized string of their database identifier field or, if the class |
||
| 78 | * has no identifier, the SPL object hash. Serializing the identifier allows |
||
| 79 | * differentiation of values that may be equal (via type juggling) but not |
||
| 80 | * identical. |
||
| 81 | * |
||
| 82 | * Since all classes in a hierarchy must share the same identifier set, |
||
| 83 | * we always take the root class name of the hierarchy. |
||
| 84 | * |
||
| 85 | * @var array |
||
| 86 | */ |
||
| 87 | private $identityMap = array(); |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Map of all identifiers of managed documents. |
||
| 91 | * Keys are object ids (spl_object_hash). |
||
| 92 | * |
||
| 93 | * @var array |
||
| 94 | */ |
||
| 95 | private $documentIdentifiers = array(); |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Map of the original document data of managed documents. |
||
| 99 | * Keys are object ids (spl_object_hash). This is used for calculating changesets |
||
| 100 | * at commit time. |
||
| 101 | * |
||
| 102 | * @var array |
||
| 103 | * @internal Note that PHPs "copy-on-write" behavior helps a lot with memory usage. |
||
| 104 | * A value will only really be copied if the value in the document is modified |
||
| 105 | * by the user. |
||
| 106 | */ |
||
| 107 | private $originalDocumentData = array(); |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Map of document changes. Keys are object ids (spl_object_hash). |
||
| 111 | * Filled at the beginning of a commit of the UnitOfWork and cleaned at the end. |
||
| 112 | * |
||
| 113 | * @var array |
||
| 114 | */ |
||
| 115 | private $documentChangeSets = array(); |
||
| 116 | |||
| 117 | /** |
||
| 118 | * The (cached) states of any known documents. |
||
| 119 | * Keys are object ids (spl_object_hash). |
||
| 120 | * |
||
| 121 | * @var array |
||
| 122 | */ |
||
| 123 | private $documentStates = array(); |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Map of documents that are scheduled for dirty checking at commit time. |
||
| 127 | * |
||
| 128 | * Documents are grouped by their class name, and then indexed by their SPL |
||
| 129 | * object hash. This is only used for documents with a change tracking |
||
| 130 | * policy of DEFERRED_EXPLICIT. |
||
| 131 | * |
||
| 132 | * @var array |
||
| 133 | * @todo rename: scheduledForSynchronization |
||
| 134 | */ |
||
| 135 | private $scheduledForDirtyCheck = array(); |
||
| 136 | |||
| 137 | /** |
||
| 138 | * A list of all pending document insertions. |
||
| 139 | * |
||
| 140 | * @var array |
||
| 141 | */ |
||
| 142 | private $documentInsertions = array(); |
||
| 143 | |||
| 144 | /** |
||
| 145 | * A list of all pending document updates. |
||
| 146 | * |
||
| 147 | * @var array |
||
| 148 | */ |
||
| 149 | private $documentUpdates = array(); |
||
| 150 | |||
| 151 | /** |
||
| 152 | * A list of all pending document upserts. |
||
| 153 | * |
||
| 154 | * @var array |
||
| 155 | */ |
||
| 156 | private $documentUpserts = array(); |
||
| 157 | |||
| 158 | /** |
||
| 159 | * A list of all pending document deletions. |
||
| 160 | * |
||
| 161 | * @var array |
||
| 162 | */ |
||
| 163 | private $documentDeletions = array(); |
||
| 164 | |||
| 165 | /** |
||
| 166 | * All pending collection deletions. |
||
| 167 | * |
||
| 168 | * @var array |
||
| 169 | */ |
||
| 170 | private $collectionDeletions = array(); |
||
| 171 | |||
| 172 | /** |
||
| 173 | * All pending collection updates. |
||
| 174 | * |
||
| 175 | * @var array |
||
| 176 | */ |
||
| 177 | private $collectionUpdates = array(); |
||
| 178 | |||
| 179 | /** |
||
| 180 | * A list of documents related to collections scheduled for update or deletion |
||
| 181 | * |
||
| 182 | * @var array |
||
| 183 | */ |
||
| 184 | private $hasScheduledCollections = array(); |
||
| 185 | |||
| 186 | /** |
||
| 187 | * List of collections visited during changeset calculation on a commit-phase of a UnitOfWork. |
||
| 188 | * At the end of the UnitOfWork all these collections will make new snapshots |
||
| 189 | * of their data. |
||
| 190 | * |
||
| 191 | * @var array |
||
| 192 | */ |
||
| 193 | private $visitedCollections = array(); |
||
| 194 | |||
| 195 | /** |
||
| 196 | * The DocumentManager that "owns" this UnitOfWork instance. |
||
| 197 | * |
||
| 198 | * @var DocumentManager |
||
| 199 | */ |
||
| 200 | private $dm; |
||
| 201 | |||
| 202 | /** |
||
| 203 | * The EventManager used for dispatching events. |
||
| 204 | * |
||
| 205 | * @var EventManager |
||
| 206 | */ |
||
| 207 | private $evm; |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Additional documents that are scheduled for removal. |
||
| 211 | * |
||
| 212 | * @var array |
||
| 213 | */ |
||
| 214 | private $orphanRemovals = array(); |
||
| 215 | |||
| 216 | /** |
||
| 217 | * The HydratorFactory used for hydrating array Mongo documents to Doctrine object documents. |
||
| 218 | * |
||
| 219 | * @var HydratorFactory |
||
| 220 | */ |
||
| 221 | private $hydratorFactory; |
||
| 222 | |||
| 223 | /** |
||
| 224 | * The document persister instances used to persist document instances. |
||
| 225 | * |
||
| 226 | * @var array |
||
| 227 | */ |
||
| 228 | private $persisters = array(); |
||
| 229 | |||
| 230 | /** |
||
| 231 | * The collection persister instance used to persist changes to collections. |
||
| 232 | * |
||
| 233 | * @var Persisters\CollectionPersister |
||
| 234 | */ |
||
| 235 | private $collectionPersister; |
||
| 236 | |||
| 237 | /** |
||
| 238 | * The persistence builder instance used in DocumentPersisters. |
||
| 239 | * |
||
| 240 | * @var PersistenceBuilder |
||
| 241 | */ |
||
| 242 | private $persistenceBuilder; |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Array of parent associations between embedded documents |
||
| 246 | * |
||
| 247 | * @todo We might need to clean up this array in clear(), doDetach(), etc. |
||
| 248 | * @var array |
||
| 249 | */ |
||
| 250 | private $parentAssociations = array(); |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Initializes a new UnitOfWork instance, bound to the given DocumentManager. |
||
| 254 | * |
||
| 255 | * @param DocumentManager $dm |
||
| 256 | * @param EventManager $evm |
||
| 257 | * @param HydratorFactory $hydratorFactory |
||
| 258 | */ |
||
| 259 | 920 | public function __construct(DocumentManager $dm, EventManager $evm, HydratorFactory $hydratorFactory) |
|
| 265 | |||
| 266 | /** |
||
| 267 | * Factory for returning new PersistenceBuilder instances used for preparing data into |
||
| 268 | * queries for insert persistence. |
||
| 269 | * |
||
| 270 | * @return PersistenceBuilder $pb |
||
| 271 | */ |
||
| 272 | 667 | public function getPersistenceBuilder() |
|
| 279 | |||
| 280 | /** |
||
| 281 | * Sets the parent association for a given embedded document. |
||
| 282 | * |
||
| 283 | * @param object $document |
||
| 284 | * @param array $mapping |
||
| 285 | * @param object $parent |
||
| 286 | * @param string $propertyPath |
||
| 287 | */ |
||
| 288 | 180 | public function setParentAssociation($document, $mapping, $parent, $propertyPath) |
|
| 293 | |||
| 294 | /** |
||
| 295 | * Gets the parent association for a given embedded document. |
||
| 296 | * |
||
| 297 | * <code> |
||
| 298 | * list($mapping, $parent, $propertyPath) = $this->getParentAssociation($embeddedDocument); |
||
| 299 | * </code> |
||
| 300 | * |
||
| 301 | * @param object $document |
||
| 302 | * @return array $association |
||
| 303 | */ |
||
| 304 | 207 | public function getParentAssociation($document) |
|
| 312 | |||
| 313 | /** |
||
| 314 | * Get the document persister instance for the given document name |
||
| 315 | * |
||
| 316 | * @param string $documentName |
||
| 317 | * @return Persisters\DocumentPersister |
||
| 318 | */ |
||
| 319 | 665 | public function getDocumentPersister($documentName) |
|
| 328 | |||
| 329 | /** |
||
| 330 | * Get the collection persister instance. |
||
| 331 | * |
||
| 332 | * @return \Doctrine\ODM\MongoDB\Persisters\CollectionPersister |
||
| 333 | */ |
||
| 334 | 665 | public function getCollectionPersister() |
|
| 342 | |||
| 343 | /** |
||
| 344 | * Set the document persister instance to use for the given document name |
||
| 345 | * |
||
| 346 | * @param string $documentName |
||
| 347 | * @param Persisters\DocumentPersister $persister |
||
| 348 | */ |
||
| 349 | 14 | public function setDocumentPersister($documentName, Persisters\DocumentPersister $persister) |
|
| 353 | |||
| 354 | /** |
||
| 355 | * Commits the UnitOfWork, executing all operations that have been postponed |
||
| 356 | * up to this point. The state of all managed documents will be synchronized with |
||
| 357 | * the database. |
||
| 358 | * |
||
| 359 | * The operations are executed in the following order: |
||
| 360 | * |
||
| 361 | * 1) All document insertions |
||
| 362 | * 2) All document updates |
||
| 363 | * 3) All document deletions |
||
| 364 | * |
||
| 365 | * @param object $document |
||
| 366 | * @param array $options Array of options to be used with batchInsert(), update() and remove() |
||
| 367 | */ |
||
| 368 | 554 | public function commit($document = null, array $options = array()) |
|
| 369 | { |
||
| 370 | // Raise preFlush |
||
| 371 | 554 | if ($this->evm->hasListeners(Events::preFlush)) { |
|
| 372 | $this->evm->dispatchEvent(Events::preFlush, new Event\PreFlushEventArgs($this->dm)); |
||
| 373 | } |
||
| 374 | |||
| 375 | 554 | $defaultOptions = $this->dm->getConfiguration()->getDefaultCommitOptions(); |
|
| 376 | 554 | if ($options) { |
|
|
|
|||
| 377 | $options = array_merge($defaultOptions, $options); |
||
| 378 | } else { |
||
| 379 | 554 | $options = $defaultOptions; |
|
| 380 | } |
||
| 381 | // Compute changes done since last commit. |
||
| 382 | 554 | if ($document === null) { |
|
| 383 | 548 | $this->computeChangeSets(); |
|
| 384 | 553 | } elseif (is_object($document)) { |
|
| 385 | 12 | $this->computeSingleDocumentChangeSet($document); |
|
| 386 | 12 | } elseif (is_array($document)) { |
|
| 387 | 1 | foreach ($document as $object) { |
|
| 388 | 1 | $this->computeSingleDocumentChangeSet($object); |
|
| 389 | 1 | } |
|
| 390 | 1 | } |
|
| 391 | |||
| 392 | 552 | if ( ! ($this->documentInsertions || |
|
| 393 | 235 | $this->documentUpserts || |
|
| 394 | 198 | $this->documentDeletions || |
|
| 395 | 188 | $this->documentUpdates || |
|
| 396 | 23 | $this->collectionUpdates || |
|
| 397 | 23 | $this->collectionDeletions || |
|
| 398 | 23 | $this->orphanRemovals) |
|
| 399 | 552 | ) { |
|
| 400 | 23 | return; // Nothing to do. |
|
| 401 | } |
||
| 402 | |||
| 403 | 549 | if ($this->orphanRemovals) { |
|
| 404 | 45 | foreach ($this->orphanRemovals as $removal) { |
|
| 405 | 45 | $this->remove($removal); |
|
| 406 | 45 | } |
|
| 407 | 45 | } |
|
| 408 | |||
| 409 | // Raise onFlush |
||
| 410 | 549 | if ($this->evm->hasListeners(Events::onFlush)) { |
|
| 411 | 7 | $this->evm->dispatchEvent(Events::onFlush, new Event\OnFlushEventArgs($this->dm)); |
|
| 412 | 7 | } |
|
| 413 | |||
| 414 | 549 | foreach ($this->getClassesForCommitAction($this->documentUpserts) as $classAndDocuments) { |
|
| 415 | 78 | list($class, $documents) = $classAndDocuments; |
|
| 416 | 78 | $this->executeUpserts($class, $documents, $options); |
|
| 417 | 549 | } |
|
| 418 | |||
| 419 | 549 | foreach ($this->getClassesForCommitAction($this->documentInsertions) as $classAndDocuments) { |
|
| 420 | 482 | list($class, $documents) = $classAndDocuments; |
|
| 421 | 482 | $this->executeInserts($class, $documents, $options); |
|
| 422 | 548 | } |
|
| 423 | |||
| 424 | 548 | foreach ($this->getClassesForCommitAction($this->documentUpdates) as $classAndDocuments) { |
|
| 425 | 214 | list($class, $documents) = $classAndDocuments; |
|
| 426 | 214 | $this->executeUpdates($class, $documents, $options); |
|
| 427 | 548 | } |
|
| 428 | |||
| 429 | 548 | foreach ($this->getClassesForCommitAction($this->documentDeletions, true) as $classAndDocuments) { |
|
| 430 | 62 | list($class, $documents) = $classAndDocuments; |
|
| 431 | 62 | $this->executeDeletions($class, $documents, $options); |
|
| 432 | 548 | } |
|
| 433 | |||
| 434 | // Raise postFlush |
||
| 435 | 548 | if ($this->evm->hasListeners(Events::postFlush)) { |
|
| 436 | $this->evm->dispatchEvent(Events::postFlush, new Event\PostFlushEventArgs($this->dm)); |
||
| 437 | } |
||
| 438 | |||
| 439 | // Clear up |
||
| 440 | 548 | $this->documentInsertions = |
|
| 441 | 548 | $this->documentUpserts = |
|
| 442 | 548 | $this->documentUpdates = |
|
| 443 | 548 | $this->documentDeletions = |
|
| 444 | 548 | $this->documentChangeSets = |
|
| 445 | 548 | $this->collectionUpdates = |
|
| 446 | 548 | $this->collectionDeletions = |
|
| 447 | 548 | $this->visitedCollections = |
|
| 448 | 548 | $this->scheduledForDirtyCheck = |
|
| 449 | 548 | $this->orphanRemovals = |
|
| 450 | 548 | $this->hasScheduledCollections = array(); |
|
| 451 | 548 | } |
|
| 452 | |||
| 453 | /** |
||
| 454 | * Groups a list of scheduled documents by their class. |
||
| 455 | * |
||
| 456 | * @param array $documents Scheduled documents (e.g. $this->documentInsertions) |
||
| 457 | * @param bool $includeEmbedded |
||
| 458 | * @return array Tuples of ClassMetadata and a corresponding array of objects |
||
| 459 | */ |
||
| 460 | 549 | private function getClassesForCommitAction($documents, $includeEmbedded = false) |
|
| 461 | { |
||
| 462 | 549 | if (empty($documents)) { |
|
| 463 | 549 | return array(); |
|
| 464 | } |
||
| 465 | 548 | $divided = array(); |
|
| 466 | 548 | $embeds = array(); |
|
| 467 | 548 | foreach ($documents as $oid => $d) { |
|
| 468 | 548 | $className = get_class($d); |
|
| 469 | 548 | if (isset($embeds[$className])) { |
|
| 470 | 68 | continue; |
|
| 471 | } |
||
| 472 | 548 | if (isset($divided[$className])) { |
|
| 473 | 135 | $divided[$className][1][$oid] = $d; |
|
| 474 | 135 | continue; |
|
| 475 | } |
||
| 476 | 548 | $class = $this->dm->getClassMetadata($className); |
|
| 477 | 548 | if ($class->isEmbeddedDocument && ! $includeEmbedded) { |
|
| 478 | 165 | $embeds[$className] = true; |
|
| 479 | 165 | continue; |
|
| 480 | } |
||
| 481 | 548 | if (empty($divided[$class->name])) { |
|
| 482 | 548 | $divided[$class->name] = array($class, array($oid => $d)); |
|
| 483 | 548 | } else { |
|
| 484 | 4 | $divided[$class->name][1][$oid] = $d; |
|
| 485 | } |
||
| 486 | 548 | } |
|
| 487 | 548 | return $divided; |
|
| 488 | } |
||
| 489 | |||
| 490 | /** |
||
| 491 | * Compute changesets of all documents scheduled for insertion. |
||
| 492 | * |
||
| 493 | * Embedded documents will not be processed. |
||
| 494 | */ |
||
| 495 | 556 | View Code Duplication | private function computeScheduleInsertsChangeSets() |
| 504 | |||
| 505 | /** |
||
| 506 | * Compute changesets of all documents scheduled for upsert. |
||
| 507 | * |
||
| 508 | * Embedded documents will not be processed. |
||
| 509 | */ |
||
| 510 | 555 | View Code Duplication | private function computeScheduleUpsertsChangeSets() |
| 519 | |||
| 520 | /** |
||
| 521 | * Only flush the given document according to a ruleset that keeps the UoW consistent. |
||
| 522 | * |
||
| 523 | * 1. All documents scheduled for insertion and (orphan) removals are processed as well! |
||
| 524 | * 2. Proxies are skipped. |
||
| 525 | * 3. Only if document is properly managed. |
||
| 526 | * |
||
| 527 | * @param object $document |
||
| 528 | * @throws \InvalidArgumentException If the document is not STATE_MANAGED |
||
| 529 | * @return void |
||
| 530 | */ |
||
| 531 | 13 | private function computeSingleDocumentChangeSet($document) |
|
| 565 | |||
| 566 | /** |
||
| 567 | * Gets the changeset for a document. |
||
| 568 | * |
||
| 569 | * @param object $document |
||
| 570 | * @return array array('property' => array(0 => mixed|null, 1 => mixed|null)) |
||
| 571 | */ |
||
| 572 | 539 | public function getDocumentChangeSet($document) |
|
| 580 | |||
| 581 | /** |
||
| 582 | * Get a documents actual data, flattening all the objects to arrays. |
||
| 583 | * |
||
| 584 | * @param object $document |
||
| 585 | * @return array |
||
| 586 | */ |
||
| 587 | 553 | public function getDocumentActualData($document) |
|
| 588 | { |
||
| 589 | 553 | $class = $this->dm->getClassMetadata(get_class($document)); |
|
| 590 | 553 | $actualData = array(); |
|
| 591 | 553 | foreach ($class->reflFields as $name => $refProp) { |
|
| 592 | 553 | $mapping = $class->fieldMappings[$name]; |
|
| 593 | // skip not saved fields |
||
| 594 | 553 | if (isset($mapping['notSaved']) && $mapping['notSaved'] === true) { |
|
| 595 | 49 | continue; |
|
| 596 | } |
||
| 597 | 553 | $value = $refProp->getValue($document); |
|
| 598 | 553 | if (isset($mapping['file']) && ! $value instanceof GridFSFile) { |
|
| 599 | 5 | $value = new GridFSFile($value); |
|
| 600 | 5 | $class->reflFields[$name]->setValue($document, $value); |
|
| 601 | 5 | $actualData[$name] = $value; |
|
| 602 | 553 | } elseif ((isset($mapping['association']) && $mapping['type'] === 'many') |
|
| 603 | 553 | && $value !== null && ! ($value instanceof PersistentCollection)) { |
|
| 604 | // If $actualData[$name] is not a Collection then use an ArrayCollection. |
||
| 605 | 365 | if ( ! $value instanceof Collection) { |
|
| 606 | 118 | $value = new ArrayCollection($value); |
|
| 607 | 118 | } |
|
| 608 | |||
| 609 | // Inject PersistentCollection |
||
| 610 | 365 | $coll = new PersistentCollection($value, $this->dm, $this); |
|
| 611 | 365 | $coll->setOwner($document, $mapping); |
|
| 612 | 365 | $coll->setDirty( ! $value->isEmpty()); |
|
| 613 | 365 | $class->reflFields[$name]->setValue($document, $coll); |
|
| 614 | 365 | $actualData[$name] = $coll; |
|
| 615 | 365 | } else { |
|
| 616 | 553 | $actualData[$name] = $value; |
|
| 617 | } |
||
| 618 | 553 | } |
|
| 619 | 553 | return $actualData; |
|
| 620 | } |
||
| 621 | |||
| 622 | /** |
||
| 623 | * Computes the changes that happened to a single document. |
||
| 624 | * |
||
| 625 | * Modifies/populates the following properties: |
||
| 626 | * |
||
| 627 | * {@link originalDocumentData} |
||
| 628 | * If the document is NEW or MANAGED but not yet fully persisted (only has an id) |
||
| 629 | * then it was not fetched from the database and therefore we have no original |
||
| 630 | * document data yet. All of the current document data is stored as the original document data. |
||
| 631 | * |
||
| 632 | * {@link documentChangeSets} |
||
| 633 | * The changes detected on all properties of the document are stored there. |
||
| 634 | * A change is a tuple array where the first entry is the old value and the second |
||
| 635 | * entry is the new value of the property. Changesets are used by persisters |
||
| 636 | * to INSERT/UPDATE the persistent document state. |
||
| 637 | * |
||
| 638 | * {@link documentUpdates} |
||
| 639 | * If the document is already fully MANAGED (has been fetched from the database before) |
||
| 640 | * and any changes to its properties are detected, then a reference to the document is stored |
||
| 641 | * there to mark it for an update. |
||
| 642 | * |
||
| 643 | * @param ClassMetadata $class The class descriptor of the document. |
||
| 644 | * @param object $document The document for which to compute the changes. |
||
| 645 | */ |
||
| 646 | 553 | public function computeChangeSet(ClassMetadata $class, $document) |
|
| 659 | |||
| 660 | /** |
||
| 661 | * Used to do the common work of computeChangeSet and recomputeSingleDocumentChangeSet |
||
| 662 | * |
||
| 663 | * @param \Doctrine\ODM\MongoDB\Mapping\ClassMetadata $class |
||
| 664 | * @param object $document |
||
| 665 | * @param boolean $recompute |
||
| 666 | */ |
||
| 667 | 553 | private function computeOrRecomputeChangeSet(ClassMetadata $class, $document, $recompute = false) |
|
| 826 | |||
| 827 | /** |
||
| 828 | * Computes all the changes that have been done to documents and collections |
||
| 829 | * since the last commit and stores these changes in the _documentChangeSet map |
||
| 830 | * temporarily for access by the persisters, until the UoW commit is finished. |
||
| 831 | */ |
||
| 832 | 551 | public function computeChangeSets() |
|
| 882 | |||
| 883 | /** |
||
| 884 | * Computes the changes of an association. |
||
| 885 | * |
||
| 886 | * @param object $parentDocument |
||
| 887 | * @param array $assoc |
||
| 888 | * @param mixed $value The value of the association. |
||
| 889 | * @throws \InvalidArgumentException |
||
| 890 | */ |
||
| 891 | 418 | private function computeAssociationChanges($parentDocument, array $assoc, $value) |
|
| 993 | |||
| 994 | /** |
||
| 995 | * INTERNAL: |
||
| 996 | * Computes the changeset of an individual document, independently of the |
||
| 997 | * computeChangeSets() routine that is used at the beginning of a UnitOfWork#commit(). |
||
| 998 | * |
||
| 999 | * The passed document must be a managed document. If the document already has a change set |
||
| 1000 | * because this method is invoked during a commit cycle then the change sets are added. |
||
| 1001 | * whereby changes detected in this method prevail. |
||
| 1002 | * |
||
| 1003 | * @ignore |
||
| 1004 | * @param ClassMetadata $class The class descriptor of the document. |
||
| 1005 | * @param object $document The document for which to (re)calculate the change set. |
||
| 1006 | * @throws \InvalidArgumentException If the passed document is not MANAGED. |
||
| 1007 | */ |
||
| 1008 | 19 | public function recomputeSingleDocumentChangeSet(ClassMetadata $class, $document) |
|
| 1027 | |||
| 1028 | /** |
||
| 1029 | * @param ClassMetadata $class |
||
| 1030 | * @param object $document |
||
| 1031 | * @throws \InvalidArgumentException If there is something wrong with document's identifier. |
||
| 1032 | */ |
||
| 1033 | 571 | private function persistNew(ClassMetadata $class, $document) |
|
| 1083 | |||
| 1084 | /** |
||
| 1085 | * Cascades the postPersist events to embedded documents. |
||
| 1086 | * |
||
| 1087 | * @param ClassMetadata $class |
||
| 1088 | * @param object $document |
||
| 1089 | */ |
||
| 1090 | 547 | private function cascadePostPersist(ClassMetadata $class, $document) |
|
| 1127 | |||
| 1128 | /** |
||
| 1129 | * Executes all document insertions for documents of the specified type. |
||
| 1130 | * |
||
| 1131 | * @param ClassMetadata $class |
||
| 1132 | * @param array $documents Array of documents to insert |
||
| 1133 | * @param array $options Array of options to be used with batchInsert() |
||
| 1134 | */ |
||
| 1135 | 482 | View Code Duplication | private function executeInserts(ClassMetadata $class, array $documents, array $options = array()) |
| 1136 | { |
||
| 1137 | 482 | $persister = $this->getDocumentPersister($class->name); |
|
| 1138 | |||
| 1139 | 482 | foreach ($documents as $oid => $document) { |
|
| 1140 | 482 | $persister->addInsert($document); |
|
| 1141 | 482 | unset($this->documentInsertions[$oid]); |
|
| 1142 | 482 | } |
|
| 1143 | |||
| 1144 | 482 | $persister->executeInserts($options); |
|
| 1145 | |||
| 1146 | 481 | $hasPostPersistLifecycleCallbacks = ! empty($class->lifecycleCallbacks[Events::postPersist]); |
|
| 1147 | 481 | $hasPostPersistListeners = $this->evm->hasListeners(Events::postPersist); |
|
| 1148 | |||
| 1149 | 481 | foreach ($documents as $document) { |
|
| 1150 | 481 | if ($hasPostPersistLifecycleCallbacks) { |
|
| 1151 | 9 | $class->invokeLifecycleCallbacks(Events::postPersist, $document); |
|
| 1152 | 9 | } |
|
| 1153 | 481 | if ($hasPostPersistListeners) { |
|
| 1154 | 5 | $this->evm->dispatchEvent(Events::postPersist, new LifecycleEventArgs($document, $this->dm)); |
|
| 1155 | 5 | } |
|
| 1156 | 481 | $this->cascadePostPersist($class, $document); |
|
| 1157 | 481 | } |
|
| 1158 | 481 | } |
|
| 1159 | |||
| 1160 | /** |
||
| 1161 | * Executes all document upserts for documents of the specified type. |
||
| 1162 | * |
||
| 1163 | * @param ClassMetadata $class |
||
| 1164 | * @param array $documents Array of documents to upsert |
||
| 1165 | * @param array $options Array of options to be used with batchInsert() |
||
| 1166 | */ |
||
| 1167 | 78 | View Code Duplication | private function executeUpserts(ClassMetadata $class, array $documents, array $options = array()) |
| 1168 | { |
||
| 1169 | 78 | $persister = $this->getDocumentPersister($class->name); |
|
| 1170 | |||
| 1171 | |||
| 1172 | 78 | foreach ($documents as $oid => $document) { |
|
| 1173 | 78 | $persister->addUpsert($document); |
|
| 1174 | 78 | unset($this->documentUpserts[$oid]); |
|
| 1175 | 78 | } |
|
| 1176 | |||
| 1177 | 78 | $persister->executeUpserts($options); |
|
| 1178 | |||
| 1179 | 78 | $hasLifecycleCallbacks = isset($class->lifecycleCallbacks[Events::postPersist]); |
|
| 1180 | 78 | $hasListeners = $this->evm->hasListeners(Events::postPersist); |
|
| 1181 | |||
| 1182 | 78 | foreach ($documents as $document) { |
|
| 1183 | 78 | if ($hasLifecycleCallbacks) { |
|
| 1184 | $class->invokeLifecycleCallbacks(Events::postPersist, $document); |
||
| 1185 | } |
||
| 1186 | 78 | if ($hasListeners) { |
|
| 1187 | 2 | $this->evm->dispatchEvent(Events::postPersist, new LifecycleEventArgs($document, $this->dm)); |
|
| 1188 | 2 | } |
|
| 1189 | 78 | $this->cascadePostPersist($class, $document); |
|
| 1190 | 78 | } |
|
| 1191 | 78 | } |
|
| 1192 | |||
| 1193 | /** |
||
| 1194 | * Executes all document updates for documents of the specified type. |
||
| 1195 | * |
||
| 1196 | * @param Mapping\ClassMetadata $class |
||
| 1197 | * @param array $documents Array of documents to update |
||
| 1198 | * @param array $options Array of options to be used with update() |
||
| 1199 | */ |
||
| 1200 | 214 | private function executeUpdates(ClassMetadata $class, array $documents, array $options = array()) |
|
| 1242 | |||
| 1243 | /** |
||
| 1244 | * Cascades the preUpdate event to embedded documents. |
||
| 1245 | * |
||
| 1246 | * @param ClassMetadata $class |
||
| 1247 | * @param object $document |
||
| 1248 | */ |
||
| 1249 | 214 | private function cascadePreUpdate(ClassMetadata $class, $document) |
|
| 1293 | |||
| 1294 | /** |
||
| 1295 | * Cascades the postUpdate and postPersist events to embedded documents. |
||
| 1296 | * |
||
| 1297 | * @param ClassMetadata $class |
||
| 1298 | * @param object $document |
||
| 1299 | */ |
||
| 1300 | 210 | private function cascadePostUpdate(ClassMetadata $class, $document) |
|
| 1347 | |||
| 1348 | /** |
||
| 1349 | * Executes all document deletions for documents of the specified type. |
||
| 1350 | * |
||
| 1351 | * @param ClassMetadata $class |
||
| 1352 | * @param array $documents Array of documents to delete |
||
| 1353 | * @param array $options Array of options to be used with remove() |
||
| 1354 | */ |
||
| 1355 | 62 | private function executeDeletions(ClassMetadata $class, array $documents, array $options = array()) |
|
| 1356 | { |
||
| 1357 | 62 | $hasPostRemoveLifecycleCallbacks = ! empty($class->lifecycleCallbacks[Events::postRemove]); |
|
| 1358 | 62 | $hasPostRemoveListeners = $this->evm->hasListeners(Events::postRemove); |
|
| 1359 | |||
| 1360 | 62 | $persister = $this->getDocumentPersister($class->name); |
|
| 1361 | |||
| 1362 | 62 | foreach ($documents as $oid => $document) { |
|
| 1363 | 62 | if ( ! $class->isEmbeddedDocument) { |
|
| 1364 | 28 | $persister->delete($document, $options); |
|
| 1365 | 26 | } |
|
| 1366 | unset( |
||
| 1367 | 60 | $this->documentDeletions[$oid], |
|
| 1368 | 60 | $this->documentIdentifiers[$oid], |
|
| 1369 | 60 | $this->originalDocumentData[$oid] |
|
| 1370 | ); |
||
| 1371 | |||
| 1372 | // Clear snapshot information for any referenced PersistentCollection |
||
| 1373 | // http://www.doctrine-project.org/jira/browse/MODM-95 |
||
| 1374 | 60 | foreach ($class->associationMappings as $fieldMapping) { |
|
| 1375 | 41 | if (isset($fieldMapping['type']) && $fieldMapping['type'] === ClassMetadata::MANY) { |
|
| 1376 | 26 | $value = $class->reflFields[$fieldMapping['fieldName']]->getValue($document); |
|
| 1377 | 26 | if ($value instanceof PersistentCollection) { |
|
| 1378 | 22 | $value->clearSnapshot(); |
|
| 1379 | 22 | } |
|
| 1380 | 26 | } |
|
| 1381 | 60 | } |
|
| 1382 | |||
| 1383 | // Document with this $oid after deletion treated as NEW, even if the $oid |
||
| 1384 | // is obtained by a new document because the old one went out of scope. |
||
| 1385 | 60 | $this->documentStates[$oid] = self::STATE_NEW; |
|
| 1386 | |||
| 1387 | 60 | if ($hasPostRemoveLifecycleCallbacks) { |
|
| 1388 | 8 | $class->invokeLifecycleCallbacks(Events::postRemove, $document); |
|
| 1389 | 8 | } |
|
| 1390 | 60 | if ($hasPostRemoveListeners) { |
|
| 1391 | 2 | $this->evm->dispatchEvent(Events::postRemove, new LifecycleEventArgs($document, $this->dm)); |
|
| 1392 | 2 | } |
|
| 1393 | 60 | } |
|
| 1394 | 60 | } |
|
| 1395 | |||
| 1396 | /** |
||
| 1397 | * Schedules a document for insertion into the database. |
||
| 1398 | * If the document already has an identifier, it will be added to the |
||
| 1399 | * identity map. |
||
| 1400 | * |
||
| 1401 | * @param ClassMetadata $class |
||
| 1402 | * @param object $document The document to schedule for insertion. |
||
| 1403 | * @throws \InvalidArgumentException |
||
| 1404 | */ |
||
| 1405 | 506 | public function scheduleForInsert(ClassMetadata $class, $document) |
|
| 1406 | { |
||
| 1407 | 506 | $oid = spl_object_hash($document); |
|
| 1408 | |||
| 1409 | 506 | if (isset($this->documentUpdates[$oid])) { |
|
| 1410 | throw new \InvalidArgumentException("Dirty document can not be scheduled for insertion."); |
||
| 1411 | } |
||
| 1412 | 506 | if (isset($this->documentDeletions[$oid])) { |
|
| 1413 | throw new \InvalidArgumentException("Removed document can not be scheduled for insertion."); |
||
| 1414 | } |
||
| 1415 | 506 | if (isset($this->documentInsertions[$oid])) { |
|
| 1416 | throw new \InvalidArgumentException("Document can not be scheduled for insertion twice."); |
||
| 1417 | } |
||
| 1418 | |||
| 1419 | 506 | $this->documentInsertions[$oid] = $document; |
|
| 1420 | |||
| 1421 | 506 | if (isset($this->documentIdentifiers[$oid])) { |
|
| 1422 | 503 | $this->addToIdentityMap($document); |
|
| 1423 | 503 | } |
|
| 1424 | 506 | } |
|
| 1425 | |||
| 1426 | /** |
||
| 1427 | * Schedules a document for upsert into the database and adds it to the |
||
| 1428 | * identity map |
||
| 1429 | * |
||
| 1430 | * @param ClassMetadata $class |
||
| 1431 | * @param object $document The document to schedule for upsert. |
||
| 1432 | * @throws \InvalidArgumentException |
||
| 1433 | */ |
||
| 1434 | 84 | public function scheduleForUpsert(ClassMetadata $class, $document) |
|
| 1435 | { |
||
| 1436 | 84 | $oid = spl_object_hash($document); |
|
| 1437 | |||
| 1438 | 84 | if ($class->isEmbeddedDocument) { |
|
| 1439 | throw new \InvalidArgumentException("Embedded document can not be scheduled for upsert."); |
||
| 1440 | } |
||
| 1441 | 84 | if (isset($this->documentUpdates[$oid])) { |
|
| 1442 | throw new \InvalidArgumentException("Dirty document can not be scheduled for upsert."); |
||
| 1443 | } |
||
| 1444 | 84 | if (isset($this->documentDeletions[$oid])) { |
|
| 1445 | throw new \InvalidArgumentException("Removed document can not be scheduled for upsert."); |
||
| 1446 | } |
||
| 1447 | 84 | if (isset($this->documentUpserts[$oid])) { |
|
| 1448 | throw new \InvalidArgumentException("Document can not be scheduled for upsert twice."); |
||
| 1449 | } |
||
| 1450 | |||
| 1451 | 84 | $this->documentUpserts[$oid] = $document; |
|
| 1452 | 84 | $this->documentIdentifiers[$oid] = $class->getIdentifierValue($document); |
|
| 1453 | 84 | $this->addToIdentityMap($document); |
|
| 1454 | 84 | } |
|
| 1455 | |||
| 1456 | /** |
||
| 1457 | * Checks whether a document is scheduled for insertion. |
||
| 1458 | * |
||
| 1459 | * @param object $document |
||
| 1460 | * @return boolean |
||
| 1461 | */ |
||
| 1462 | 70 | public function isScheduledForInsert($document) |
|
| 1463 | { |
||
| 1464 | 70 | return isset($this->documentInsertions[spl_object_hash($document)]); |
|
| 1465 | } |
||
| 1466 | |||
| 1467 | /** |
||
| 1468 | * Checks whether a document is scheduled for upsert. |
||
| 1469 | * |
||
| 1470 | * @param object $document |
||
| 1471 | * @return boolean |
||
| 1472 | */ |
||
| 1473 | 5 | public function isScheduledForUpsert($document) |
|
| 1474 | { |
||
| 1475 | 5 | return isset($this->documentUpserts[spl_object_hash($document)]); |
|
| 1476 | } |
||
| 1477 | |||
| 1478 | /** |
||
| 1479 | * Schedules a document for being updated. |
||
| 1480 | * |
||
| 1481 | * @param object $document The document to schedule for being updated. |
||
| 1482 | * @throws \InvalidArgumentException |
||
| 1483 | */ |
||
| 1484 | 223 | public function scheduleForUpdate($document) |
|
| 1501 | |||
| 1502 | /** |
||
| 1503 | * Checks whether a document is registered as dirty in the unit of work. |
||
| 1504 | * Note: Is not very useful currently as dirty documents are only registered |
||
| 1505 | * at commit time. |
||
| 1506 | * |
||
| 1507 | * @param object $document |
||
| 1508 | * @return boolean |
||
| 1509 | */ |
||
| 1510 | 13 | public function isScheduledForUpdate($document) |
|
| 1514 | |||
| 1515 | 1 | public function isScheduledForDirtyCheck($document) |
|
| 1520 | |||
| 1521 | /** |
||
| 1522 | * INTERNAL: |
||
| 1523 | * Schedules a document for deletion. |
||
| 1524 | * |
||
| 1525 | * @param object $document |
||
| 1526 | */ |
||
| 1527 | 67 | public function scheduleForDelete($document) |
|
| 1528 | { |
||
| 1529 | 67 | $oid = spl_object_hash($document); |
|
| 1530 | |||
| 1531 | 67 | if (isset($this->documentInsertions[$oid])) { |
|
| 1532 | 2 | if ($this->isInIdentityMap($document)) { |
|
| 1533 | 2 | $this->removeFromIdentityMap($document); |
|
| 1534 | 2 | } |
|
| 1535 | 2 | unset($this->documentInsertions[$oid]); |
|
| 1536 | 2 | return; // document has not been persisted yet, so nothing more to do. |
|
| 1537 | } |
||
| 1538 | |||
| 1539 | 66 | if ( ! $this->isInIdentityMap($document)) { |
|
| 1540 | 1 | return; // ignore |
|
| 1541 | } |
||
| 1542 | |||
| 1543 | 65 | $this->removeFromIdentityMap($document); |
|
| 1544 | 65 | $this->documentStates[$oid] = self::STATE_REMOVED; |
|
| 1545 | |||
| 1546 | 65 | if (isset($this->documentUpdates[$oid])) { |
|
| 1547 | unset($this->documentUpdates[$oid]); |
||
| 1548 | } |
||
| 1549 | 65 | if ( ! isset($this->documentDeletions[$oid])) { |
|
| 1550 | 65 | $this->documentDeletions[$oid] = $document; |
|
| 1551 | 65 | } |
|
| 1552 | 65 | } |
|
| 1553 | |||
| 1554 | /** |
||
| 1555 | * Checks whether a document is registered as removed/deleted with the unit |
||
| 1556 | * of work. |
||
| 1557 | * |
||
| 1558 | * @param object $document |
||
| 1559 | * @return boolean |
||
| 1560 | */ |
||
| 1561 | 8 | public function isScheduledForDelete($document) |
|
| 1565 | |||
| 1566 | /** |
||
| 1567 | * Checks whether a document is scheduled for insertion, update or deletion. |
||
| 1568 | * |
||
| 1569 | * @param $document |
||
| 1570 | * @return boolean |
||
| 1571 | */ |
||
| 1572 | 224 | public function isDocumentScheduled($document) |
|
| 1580 | |||
| 1581 | /** |
||
| 1582 | * INTERNAL: |
||
| 1583 | * Registers a document in the identity map. |
||
| 1584 | * |
||
| 1585 | * Note that documents in a hierarchy are registered with the class name of |
||
| 1586 | * the root document. Identifiers are serialized before being used as array |
||
| 1587 | * keys to allow differentiation of equal, but not identical, values. |
||
| 1588 | * |
||
| 1589 | * @ignore |
||
| 1590 | * @param object $document The document to register. |
||
| 1591 | * @return boolean TRUE if the registration was successful, FALSE if the identity of |
||
| 1592 | * the document in question is already managed. |
||
| 1593 | */ |
||
| 1594 | 598 | public function addToIdentityMap($document) |
|
| 1595 | { |
||
| 1596 | 598 | $class = $this->dm->getClassMetadata(get_class($document)); |
|
| 1597 | 598 | $id = $this->getIdForIdentityMap($document); |
|
| 1598 | |||
| 1599 | 598 | if (isset($this->identityMap[$class->name][$id])) { |
|
| 1600 | 53 | return false; |
|
| 1601 | } |
||
| 1602 | |||
| 1603 | 598 | $this->identityMap[$class->name][$id] = $document; |
|
| 1604 | |||
| 1605 | 598 | if ($document instanceof NotifyPropertyChanged && |
|
| 1606 | 598 | ( ! $document instanceof Proxy || $document->__isInitialized())) { |
|
| 1607 | 3 | $document->addPropertyChangedListener($this); |
|
| 1608 | 3 | } |
|
| 1609 | |||
| 1610 | 598 | return true; |
|
| 1611 | } |
||
| 1612 | |||
| 1613 | /** |
||
| 1614 | * Gets the state of a document with regard to the current unit of work. |
||
| 1615 | * |
||
| 1616 | * @param object $document |
||
| 1617 | * @param int|null $assume The state to assume if the state is not yet known (not MANAGED or REMOVED). |
||
| 1618 | * This parameter can be set to improve performance of document state detection |
||
| 1619 | * by potentially avoiding a database lookup if the distinction between NEW and DETACHED |
||
| 1620 | * is either known or does not matter for the caller of the method. |
||
| 1621 | * @return int The document state. |
||
| 1622 | */ |
||
| 1623 | 574 | public function getDocumentState($document, $assume = null) |
|
| 1673 | |||
| 1674 | /** |
||
| 1675 | * INTERNAL: |
||
| 1676 | * Removes a document from the identity map. This effectively detaches the |
||
| 1677 | * document from the persistence management of Doctrine. |
||
| 1678 | * |
||
| 1679 | * @ignore |
||
| 1680 | * @param object $document |
||
| 1681 | * @throws \InvalidArgumentException |
||
| 1682 | * @return boolean |
||
| 1683 | */ |
||
| 1684 | 76 | public function removeFromIdentityMap($document) |
|
| 1685 | { |
||
| 1686 | 76 | $oid = spl_object_hash($document); |
|
| 1687 | |||
| 1688 | // Check if id is registered first |
||
| 1689 | 76 | if ( ! isset($this->documentIdentifiers[$oid])) { |
|
| 1690 | return false; |
||
| 1691 | } |
||
| 1692 | |||
| 1693 | 76 | $class = $this->dm->getClassMetadata(get_class($document)); |
|
| 1694 | 76 | $id = $this->getIdForIdentityMap($document); |
|
| 1695 | |||
| 1696 | 76 | if (isset($this->identityMap[$class->name][$id])) { |
|
| 1697 | 76 | unset($this->identityMap[$class->name][$id]); |
|
| 1698 | 76 | $this->documentStates[$oid] = self::STATE_DETACHED; |
|
| 1699 | 76 | return true; |
|
| 1700 | } |
||
| 1701 | |||
| 1702 | return false; |
||
| 1703 | } |
||
| 1704 | |||
| 1705 | /** |
||
| 1706 | * INTERNAL: |
||
| 1707 | * Gets a document in the identity map by its identifier hash. |
||
| 1708 | * |
||
| 1709 | * @ignore |
||
| 1710 | * @param mixed $id Document identifier |
||
| 1711 | * @param ClassMetadata $class Document class |
||
| 1712 | * @return object |
||
| 1713 | * @throws InvalidArgumentException if the class does not have an identifier |
||
| 1714 | */ |
||
| 1715 | 31 | public function getById($id, ClassMetadata $class) |
|
| 1725 | |||
| 1726 | /** |
||
| 1727 | * INTERNAL: |
||
| 1728 | * Tries to get a document by its identifier hash. If no document is found |
||
| 1729 | * for the given hash, FALSE is returned. |
||
| 1730 | * |
||
| 1731 | * @ignore |
||
| 1732 | * @param mixed $id Document identifier |
||
| 1733 | * @param ClassMetadata $class Document class |
||
| 1734 | * @return mixed The found document or FALSE. |
||
| 1735 | * @throws InvalidArgumentException if the class does not have an identifier |
||
| 1736 | */ |
||
| 1737 | 290 | public function tryGetById($id, ClassMetadata $class) |
|
| 1748 | |||
| 1749 | /** |
||
| 1750 | * Schedules a document for dirty-checking at commit-time. |
||
| 1751 | * |
||
| 1752 | * @param object $document The document to schedule for dirty-checking. |
||
| 1753 | * @todo Rename: scheduleForSynchronization |
||
| 1754 | */ |
||
| 1755 | 2 | public function scheduleForDirtyCheck($document) |
|
| 1760 | |||
| 1761 | /** |
||
| 1762 | * Checks whether a document is registered in the identity map. |
||
| 1763 | * |
||
| 1764 | * @param object $document |
||
| 1765 | * @return boolean |
||
| 1766 | */ |
||
| 1767 | 76 | public function isInIdentityMap($document) |
|
| 1768 | { |
||
| 1769 | 76 | $oid = spl_object_hash($document); |
|
| 1770 | |||
| 1771 | 76 | if ( ! isset($this->documentIdentifiers[$oid])) { |
|
| 1772 | 4 | return false; |
|
| 1773 | } |
||
| 1774 | |||
| 1775 | 75 | $class = $this->dm->getClassMetadata(get_class($document)); |
|
| 1776 | 75 | $id = $this->getIdForIdentityMap($document); |
|
| 1777 | |||
| 1778 | 75 | return isset($this->identityMap[$class->name][$id]); |
|
| 1779 | } |
||
| 1780 | |||
| 1781 | /** |
||
| 1782 | * @param object $document |
||
| 1783 | * @return string |
||
| 1784 | */ |
||
| 1785 | 598 | private function getIdForIdentityMap($document) |
|
| 1786 | { |
||
| 1787 | 598 | $class = $this->dm->getClassMetadata(get_class($document)); |
|
| 1788 | |||
| 1789 | 598 | if ( ! $class->identifier) { |
|
| 1790 | 145 | $id = spl_object_hash($document); |
|
| 1791 | 145 | } else { |
|
| 1792 | 597 | $id = $this->documentIdentifiers[spl_object_hash($document)]; |
|
| 1793 | 597 | $id = serialize($class->getDatabaseIdentifierValue($id)); |
|
| 1794 | } |
||
| 1795 | |||
| 1796 | 598 | return $id; |
|
| 1797 | } |
||
| 1798 | |||
| 1799 | /** |
||
| 1800 | * INTERNAL: |
||
| 1801 | * Checks whether an identifier exists in the identity map. |
||
| 1802 | * |
||
| 1803 | * @ignore |
||
| 1804 | * @param string $id |
||
| 1805 | * @param string $rootClassName |
||
| 1806 | * @return boolean |
||
| 1807 | */ |
||
| 1808 | public function containsId($id, $rootClassName) |
||
| 1812 | |||
| 1813 | /** |
||
| 1814 | * Persists a document as part of the current unit of work. |
||
| 1815 | * |
||
| 1816 | * @param object $document The document to persist. |
||
| 1817 | * @throws MongoDBException If trying to persist MappedSuperclass. |
||
| 1818 | * @throws \InvalidArgumentException If there is something wrong with document's identifier. |
||
| 1819 | */ |
||
| 1820 | 569 | public function persist($document) |
|
| 1829 | |||
| 1830 | /** |
||
| 1831 | * Saves a document as part of the current unit of work. |
||
| 1832 | * This method is internally called during save() cascades as it tracks |
||
| 1833 | * the already visited documents to prevent infinite recursions. |
||
| 1834 | * |
||
| 1835 | * NOTE: This method always considers documents that are not yet known to |
||
| 1836 | * this UnitOfWork as NEW. |
||
| 1837 | * |
||
| 1838 | * @param object $document The document to persist. |
||
| 1839 | * @param array $visited The already visited documents. |
||
| 1840 | * @throws \InvalidArgumentException |
||
| 1841 | * @throws MongoDBException |
||
| 1842 | */ |
||
| 1843 | 568 | private function doPersist($document, array &$visited) |
|
| 1884 | |||
| 1885 | /** |
||
| 1886 | * Deletes a document as part of the current unit of work. |
||
| 1887 | * |
||
| 1888 | * @param object $document The document to remove. |
||
| 1889 | */ |
||
| 1890 | 66 | public function remove($document) |
|
| 1895 | |||
| 1896 | /** |
||
| 1897 | * Deletes a document as part of the current unit of work. |
||
| 1898 | * |
||
| 1899 | * This method is internally called during delete() cascades as it tracks |
||
| 1900 | * the already visited documents to prevent infinite recursions. |
||
| 1901 | * |
||
| 1902 | * @param object $document The document to delete. |
||
| 1903 | * @param array $visited The map of the already visited documents. |
||
| 1904 | * @throws MongoDBException |
||
| 1905 | */ |
||
| 1906 | 66 | private function doRemove($document, array &$visited) |
|
| 1943 | |||
| 1944 | /** |
||
| 1945 | * Merges the state of the given detached document into this UnitOfWork. |
||
| 1946 | * |
||
| 1947 | * @param object $document |
||
| 1948 | * @return object The managed copy of the document. |
||
| 1949 | */ |
||
| 1950 | 13 | public function merge($document) |
|
| 1956 | |||
| 1957 | /** |
||
| 1958 | * Executes a merge operation on a document. |
||
| 1959 | * |
||
| 1960 | * @param object $document |
||
| 1961 | * @param array $visited |
||
| 1962 | * @param object|null $prevManagedCopy |
||
| 1963 | * @param array|null $assoc |
||
| 1964 | * |
||
| 1965 | * @return object The managed copy of the document. |
||
| 1966 | * |
||
| 1967 | * @throws InvalidArgumentException If the entity instance is NEW. |
||
| 1968 | * @throws LockException If the document uses optimistic locking through a |
||
| 1969 | * version attribute and the version check against the |
||
| 1970 | * managed copy fails. |
||
| 1971 | */ |
||
| 1972 | 13 | private function doMerge($document, array &$visited, $prevManagedCopy = null, $assoc = null) |
|
| 2150 | |||
| 2151 | /** |
||
| 2152 | * Detaches a document from the persistence management. It's persistence will |
||
| 2153 | * no longer be managed by Doctrine. |
||
| 2154 | * |
||
| 2155 | * @param object $document The document to detach. |
||
| 2156 | */ |
||
| 2157 | 9 | public function detach($document) |
|
| 2162 | |||
| 2163 | /** |
||
| 2164 | * Executes a detach operation on the given document. |
||
| 2165 | * |
||
| 2166 | * @param object $document |
||
| 2167 | * @param array $visited |
||
| 2168 | * @internal This method always considers documents with an assigned identifier as DETACHED. |
||
| 2169 | */ |
||
| 2170 | 12 | private function doDetach($document, array &$visited) |
|
| 2195 | |||
| 2196 | /** |
||
| 2197 | * Refreshes the state of the given document from the database, overwriting |
||
| 2198 | * any local, unpersisted changes. |
||
| 2199 | * |
||
| 2200 | * @param object $document The document to refresh. |
||
| 2201 | * @throws \InvalidArgumentException If the document is not MANAGED. |
||
| 2202 | */ |
||
| 2203 | 20 | public function refresh($document) |
|
| 2208 | |||
| 2209 | /** |
||
| 2210 | * Executes a refresh operation on a document. |
||
| 2211 | * |
||
| 2212 | * @param object $document The document to refresh. |
||
| 2213 | * @param array $visited The already visited documents during cascades. |
||
| 2214 | * @throws \InvalidArgumentException If the document is not MANAGED. |
||
| 2215 | */ |
||
| 2216 | 20 | private function doRefresh($document, array &$visited) |
|
| 2238 | |||
| 2239 | /** |
||
| 2240 | * Cascades a refresh operation to associated documents. |
||
| 2241 | * |
||
| 2242 | * @param object $document |
||
| 2243 | * @param array $visited |
||
| 2244 | */ |
||
| 2245 | 19 | private function cascadeRefresh($document, array &$visited) |
|
| 2269 | |||
| 2270 | /** |
||
| 2271 | * Cascades a detach operation to associated documents. |
||
| 2272 | * |
||
| 2273 | * @param object $document |
||
| 2274 | * @param array $visited |
||
| 2275 | */ |
||
| 2276 | 12 | View Code Duplication | private function cascadeDetach($document, array &$visited) |
| 2297 | /** |
||
| 2298 | * Cascades a merge operation to associated documents. |
||
| 2299 | * |
||
| 2300 | * @param object $document |
||
| 2301 | * @param object $managedCopy |
||
| 2302 | * @param array $visited |
||
| 2303 | */ |
||
| 2304 | 13 | private function cascadeMerge($document, $managedCopy, array &$visited) |
|
| 2335 | |||
| 2336 | /** |
||
| 2337 | * Cascades the save operation to associated documents. |
||
| 2338 | * |
||
| 2339 | * @param object $document |
||
| 2340 | * @param array $visited |
||
| 2341 | */ |
||
| 2342 | 566 | private function cascadePersist($document, array &$visited) |
|
| 2389 | |||
| 2390 | /** |
||
| 2391 | * Cascades the delete operation to associated documents. |
||
| 2392 | * |
||
| 2393 | * @param object $document |
||
| 2394 | * @param array $visited |
||
| 2395 | */ |
||
| 2396 | 66 | View Code Duplication | private function cascadeRemove($document, array &$visited) |
| 2418 | |||
| 2419 | /** |
||
| 2420 | * Acquire a lock on the given document. |
||
| 2421 | * |
||
| 2422 | * @param object $document |
||
| 2423 | * @param int $lockMode |
||
| 2424 | * @param int $lockVersion |
||
| 2425 | * @throws LockException |
||
| 2426 | * @throws \InvalidArgumentException |
||
| 2427 | */ |
||
| 2428 | 9 | public function lock($document, $lockMode, $lockVersion = null) |
|
| 2452 | |||
| 2453 | /** |
||
| 2454 | * Releases a lock on the given document. |
||
| 2455 | * |
||
| 2456 | * @param object $document |
||
| 2457 | * @throws \InvalidArgumentException |
||
| 2458 | */ |
||
| 2459 | 1 | public function unlock($document) |
|
| 2467 | |||
| 2468 | /** |
||
| 2469 | * Clears the UnitOfWork. |
||
| 2470 | * |
||
| 2471 | * @param string|null $documentName if given, only documents of this type will get detached. |
||
| 2472 | */ |
||
| 2473 | 386 | public function clear($documentName = null) |
|
| 2506 | |||
| 2507 | /** |
||
| 2508 | * INTERNAL: |
||
| 2509 | * Schedules an embedded document for removal. The remove() operation will be |
||
| 2510 | * invoked on that document at the beginning of the next commit of this |
||
| 2511 | * UnitOfWork. |
||
| 2512 | * |
||
| 2513 | * @ignore |
||
| 2514 | * @param object $document |
||
| 2515 | */ |
||
| 2516 | 47 | public function scheduleOrphanRemoval($document) |
|
| 2520 | |||
| 2521 | /** |
||
| 2522 | * INTERNAL: |
||
| 2523 | * Unschedules an embedded or referenced object for removal. |
||
| 2524 | * |
||
| 2525 | * @ignore |
||
| 2526 | * @param object $document |
||
| 2527 | */ |
||
| 2528 | 103 | public function unscheduleOrphanRemoval($document) |
|
| 2535 | |||
| 2536 | /** |
||
| 2537 | * Fixes PersistentCollection state if it wasn't used exactly as we had in mind: |
||
| 2538 | * 1) sets owner if it was cloned |
||
| 2539 | * 2) clones collection, sets owner, updates document's property and, if necessary, updates originalData |
||
| 2540 | * 3) NOP if state is OK |
||
| 2541 | * Returned collection should be used from now on (only important with 2nd point) |
||
| 2542 | * |
||
| 2543 | * @param PersistentCollection $coll |
||
| 2544 | * @param object $document |
||
| 2545 | * @param ClassMetadata $class |
||
| 2546 | * @param string $propName |
||
| 2547 | * @return PersistentCollection |
||
| 2548 | */ |
||
| 2549 | 8 | private function fixPersistentCollectionOwnership(PersistentCollection $coll, $document, ClassMetadata $class, $propName) |
|
| 2550 | { |
||
| 2551 | 8 | $owner = $coll->getOwner(); |
|
| 2552 | 8 | if ($owner === null) { // cloned |
|
| 2553 | 6 | $coll->setOwner($document, $class->fieldMappings[$propName]); |
|
| 2554 | 8 | } elseif ($owner !== $document) { // no clone, we have to fix |
|
| 2555 | 2 | if ( ! $coll->isInitialized()) { |
|
| 2556 | 1 | $coll->initialize(); // we have to do this otherwise the cols share state |
|
| 2557 | 1 | } |
|
| 2558 | 2 | $newValue = clone $coll; |
|
| 2559 | 2 | $newValue->setOwner($document, $class->fieldMappings[$propName]); |
|
| 2560 | 2 | $class->reflFields[$propName]->setValue($document, $newValue); |
|
| 2561 | 2 | if ($this->isScheduledForUpdate($document)) { |
|
| 2562 | // @todo following line should be superfluous once collections are stored in change sets |
||
| 2563 | $this->setOriginalDocumentProperty(spl_object_hash($document), $propName, $newValue); |
||
| 2564 | } |
||
| 2565 | 2 | return $newValue; |
|
| 2566 | } |
||
| 2567 | 6 | return $coll; |
|
| 2568 | } |
||
| 2569 | |||
| 2570 | /** |
||
| 2571 | * INTERNAL: |
||
| 2572 | * Schedules a complete collection for removal when this UnitOfWork commits. |
||
| 2573 | * |
||
| 2574 | * @param PersistentCollection $coll |
||
| 2575 | */ |
||
| 2576 | 41 | public function scheduleCollectionDeletion(PersistentCollection $coll) |
|
| 2577 | { |
||
| 2578 | 41 | $oid = spl_object_hash($coll); |
|
| 2579 | 41 | unset($this->collectionUpdates[$oid]); |
|
| 2580 | 41 | if ( ! isset($this->collectionDeletions[$oid])) { |
|
| 2581 | 41 | $this->collectionDeletions[$oid] = $coll; |
|
| 2582 | 41 | $this->scheduleCollectionOwner($coll); |
|
| 2583 | 41 | } |
|
| 2584 | 41 | } |
|
| 2585 | |||
| 2586 | /** |
||
| 2587 | * Checks whether a PersistentCollection is scheduled for deletion. |
||
| 2588 | * |
||
| 2589 | * @param PersistentCollection $coll |
||
| 2590 | * @return boolean |
||
| 2591 | */ |
||
| 2592 | 106 | public function isCollectionScheduledForDeletion(PersistentCollection $coll) |
|
| 2593 | { |
||
| 2594 | 106 | return isset($this->collectionDeletions[spl_object_hash($coll)]); |
|
| 2595 | } |
||
| 2596 | |||
| 2597 | /** |
||
| 2598 | * INTERNAL: |
||
| 2599 | * Unschedules a collection from being deleted when this UnitOfWork commits. |
||
| 2600 | * |
||
| 2601 | * @param \Doctrine\ODM\MongoDB\PersistentCollection $coll |
||
| 2602 | */ |
||
| 2603 | 205 | View Code Duplication | public function unscheduleCollectionDeletion(PersistentCollection $coll) |
| 2612 | |||
| 2613 | /** |
||
| 2614 | * INTERNAL: |
||
| 2615 | * Schedules a collection for update when this UnitOfWork commits. |
||
| 2616 | * |
||
| 2617 | * @param PersistentCollection $coll |
||
| 2618 | */ |
||
| 2619 | 221 | public function scheduleCollectionUpdate(PersistentCollection $coll) |
|
| 2634 | |||
| 2635 | /** |
||
| 2636 | * INTERNAL: |
||
| 2637 | * Unschedules a collection from being updated when this UnitOfWork commits. |
||
| 2638 | * |
||
| 2639 | * @param \Doctrine\ODM\MongoDB\PersistentCollection $coll |
||
| 2640 | */ |
||
| 2641 | 205 | View Code Duplication | public function unscheduleCollectionUpdate(PersistentCollection $coll) |
| 2650 | |||
| 2651 | /** |
||
| 2652 | * Checks whether a PersistentCollection is scheduled for update. |
||
| 2653 | * |
||
| 2654 | * @param PersistentCollection $coll |
||
| 2655 | * @return boolean |
||
| 2656 | */ |
||
| 2657 | 122 | public function isCollectionScheduledForUpdate(PersistentCollection $coll) |
|
| 2661 | |||
| 2662 | /** |
||
| 2663 | * INTERNAL: |
||
| 2664 | * Gets PersistentCollections that have been visited during computing change |
||
| 2665 | * set of $document |
||
| 2666 | * |
||
| 2667 | * @param object $document |
||
| 2668 | * @return PersistentCollection[] |
||
| 2669 | */ |
||
| 2670 | 534 | public function getVisitedCollections($document) |
|
| 2677 | |||
| 2678 | /** |
||
| 2679 | * INTERNAL: |
||
| 2680 | * Gets PersistentCollections that are scheduled to update and related to $document |
||
| 2681 | * |
||
| 2682 | * @param object $document |
||
| 2683 | * @return array |
||
| 2684 | */ |
||
| 2685 | 534 | public function getScheduledCollections($document) |
|
| 2692 | |||
| 2693 | /** |
||
| 2694 | * Checks whether the document is related to a PersistentCollection |
||
| 2695 | * scheduled for update or deletion. |
||
| 2696 | * |
||
| 2697 | * @param object $document |
||
| 2698 | * @return boolean |
||
| 2699 | */ |
||
| 2700 | 59 | public function hasScheduledCollections($document) |
|
| 2704 | |||
| 2705 | /** |
||
| 2706 | * Marks the PersistentCollection's top-level owner as having a relation to |
||
| 2707 | * a collection scheduled for update or deletion. |
||
| 2708 | * |
||
| 2709 | * If the owner is not scheduled for any lifecycle action, it will be |
||
| 2710 | * scheduled for update to ensure that versioning takes place if necessary. |
||
| 2711 | * |
||
| 2712 | * If the collection is nested within atomic collection, it is immediately |
||
| 2713 | * unscheduled and atomic one is scheduled for update instead. This makes |
||
| 2714 | * calculating update data way easier. |
||
| 2715 | * |
||
| 2716 | * @param PersistentCollection $coll |
||
| 2717 | */ |
||
| 2718 | 223 | private function scheduleCollectionOwner(PersistentCollection $coll) |
|
| 2741 | |||
| 2742 | /** |
||
| 2743 | * Get the top-most owning document of a given document |
||
| 2744 | * |
||
| 2745 | * If a top-level document is provided, that same document will be returned. |
||
| 2746 | * For an embedded document, we will walk through parent associations until |
||
| 2747 | * we find a top-level document. |
||
| 2748 | * |
||
| 2749 | * @param object $document |
||
| 2750 | * @throws \UnexpectedValueException when a top-level document could not be found |
||
| 2751 | * @return object |
||
| 2752 | */ |
||
| 2753 | 225 | public function getOwningDocument($document) |
|
| 2769 | |||
| 2770 | /** |
||
| 2771 | * Gets the class name for an association (embed or reference) with respect |
||
| 2772 | * to any discriminator value. |
||
| 2773 | * |
||
| 2774 | * @param array $mapping Field mapping for the association |
||
| 2775 | * @param array|null $data Data for the embedded document or reference |
||
| 2776 | */ |
||
| 2777 | 207 | public function getClassNameForAssociation(array $mapping, $data) |
|
| 2778 | { |
||
| 2779 | 207 | $discriminatorField = isset($mapping['discriminatorField']) ? $mapping['discriminatorField'] : null; |
|
| 2780 | |||
| 2781 | 207 | $discriminatorValue = null; |
|
| 2782 | 207 | if (isset($discriminatorField, $data[$discriminatorField])) { |
|
| 2783 | 21 | $discriminatorValue = $data[$discriminatorField]; |
|
| 2784 | 207 | } elseif (isset($mapping['defaultDiscriminatorValue'])) { |
|
| 2785 | $discriminatorValue = $mapping['defaultDiscriminatorValue']; |
||
| 2786 | } |
||
| 2787 | |||
| 2788 | 207 | if ($discriminatorValue !== null) { |
|
| 2789 | 21 | return isset($mapping['discriminatorMap'][$discriminatorValue]) |
|
| 2790 | 21 | ? $mapping['discriminatorMap'][$discriminatorValue] |
|
| 2791 | 21 | : $discriminatorValue; |
|
| 2792 | } |
||
| 2793 | |||
| 2794 | 187 | $class = $this->dm->getClassMetadata($mapping['targetDocument']); |
|
| 2795 | |||
| 2796 | 187 | View Code Duplication | if (isset($class->discriminatorField, $data[$class->discriminatorField])) { |
| 2797 | 15 | $discriminatorValue = $data[$class->discriminatorField]; |
|
| 2798 | 187 | } elseif ($class->defaultDiscriminatorValue !== null) { |
|
| 2799 | 1 | $discriminatorValue = $class->defaultDiscriminatorValue; |
|
| 2800 | 1 | } |
|
| 2801 | |||
| 2802 | 187 | if ($discriminatorValue !== null) { |
|
| 2803 | 16 | return isset($class->discriminatorMap[$discriminatorValue]) |
|
| 2804 | 16 | ? $class->discriminatorMap[$discriminatorValue] |
|
| 2805 | 16 | : $discriminatorValue; |
|
| 2806 | } |
||
| 2807 | |||
| 2808 | 171 | return $mapping['targetDocument']; |
|
| 2809 | } |
||
| 2810 | |||
| 2811 | /** |
||
| 2812 | * INTERNAL: |
||
| 2813 | * Creates a document. Used for reconstitution of documents during hydration. |
||
| 2814 | * |
||
| 2815 | * @ignore |
||
| 2816 | * @param string $className The name of the document class. |
||
| 2817 | * @param array $data The data for the document. |
||
| 2818 | * @param array $hints Any hints to account for during reconstitution/lookup of the document. |
||
| 2819 | * @param object The document to be hydrated into in case of creation |
||
| 2820 | * @return object The document instance. |
||
| 2821 | * @internal Highly performance-sensitive method. |
||
| 2822 | */ |
||
| 2823 | 380 | public function getOrCreateDocument($className, $data, &$hints = array(), $document = null) |
|
| 2877 | |||
| 2878 | /** |
||
| 2879 | * Initializes (loads) an uninitialized persistent collection of a document. |
||
| 2880 | * |
||
| 2881 | * @param PersistentCollection $collection The collection to initialize. |
||
| 2882 | */ |
||
| 2883 | 157 | public function loadCollection(PersistentCollection $collection) |
|
| 2887 | |||
| 2888 | /** |
||
| 2889 | * Gets the identity map of the UnitOfWork. |
||
| 2890 | * |
||
| 2891 | * @return array |
||
| 2892 | */ |
||
| 2893 | public function getIdentityMap() |
||
| 2897 | |||
| 2898 | /** |
||
| 2899 | * Gets the original data of a document. The original data is the data that was |
||
| 2900 | * present at the time the document was reconstituted from the database. |
||
| 2901 | * |
||
| 2902 | * @param object $document |
||
| 2903 | * @return array |
||
| 2904 | */ |
||
| 2905 | 1 | public function getOriginalDocumentData($document) |
|
| 2913 | |||
| 2914 | /** |
||
| 2915 | * @ignore |
||
| 2916 | */ |
||
| 2917 | 50 | public function setOriginalDocumentData($document, array $data) |
|
| 2921 | |||
| 2922 | /** |
||
| 2923 | * INTERNAL: |
||
| 2924 | * Sets a property value of the original data array of a document. |
||
| 2925 | * |
||
| 2926 | * @ignore |
||
| 2927 | * @param string $oid |
||
| 2928 | * @param string $property |
||
| 2929 | * @param mixed $value |
||
| 2930 | */ |
||
| 2931 | 3 | public function setOriginalDocumentProperty($oid, $property, $value) |
|
| 2935 | |||
| 2936 | /** |
||
| 2937 | * Gets the identifier of a document. |
||
| 2938 | * |
||
| 2939 | * @param object $document |
||
| 2940 | * @return mixed The identifier value |
||
| 2941 | */ |
||
| 2942 | 353 | public function getDocumentIdentifier($document) |
|
| 2947 | |||
| 2948 | /** |
||
| 2949 | * Checks whether the UnitOfWork has any pending insertions. |
||
| 2950 | * |
||
| 2951 | * @return boolean TRUE if this UnitOfWork has pending insertions, FALSE otherwise. |
||
| 2952 | */ |
||
| 2953 | public function hasPendingInsertions() |
||
| 2957 | |||
| 2958 | /** |
||
| 2959 | * Calculates the size of the UnitOfWork. The size of the UnitOfWork is the |
||
| 2960 | * number of documents in the identity map. |
||
| 2961 | * |
||
| 2962 | * @return integer |
||
| 2963 | */ |
||
| 2964 | 2 | public function size() |
|
| 2972 | |||
| 2973 | /** |
||
| 2974 | * INTERNAL: |
||
| 2975 | * Registers a document as managed. |
||
| 2976 | * |
||
| 2977 | * TODO: This method assumes that $id is a valid PHP identifier for the |
||
| 2978 | * document class. If the class expects its database identifier to be a |
||
| 2979 | * MongoId, and an incompatible $id is registered (e.g. an integer), the |
||
| 2980 | * document identifiers map will become inconsistent with the identity map. |
||
| 2981 | * In the future, we may want to round-trip $id through a PHP and database |
||
| 2982 | * conversion and throw an exception if it's inconsistent. |
||
| 2983 | * |
||
| 2984 | * @param object $document The document. |
||
| 2985 | * @param array $id The identifier values. |
||
| 2986 | * @param array $data The original document data. |
||
| 2987 | */ |
||
| 2988 | 374 | public function registerManaged($document, $id, array $data) |
|
| 3003 | |||
| 3004 | /** |
||
| 3005 | * INTERNAL: |
||
| 3006 | * Clears the property changeset of the document with the given OID. |
||
| 3007 | * |
||
| 3008 | * @param string $oid The document's OID. |
||
| 3009 | */ |
||
| 3010 | 1 | public function clearDocumentChangeSet($oid) |
|
| 3014 | |||
| 3015 | /* PropertyChangedListener implementation */ |
||
| 3016 | |||
| 3017 | /** |
||
| 3018 | * Notifies this UnitOfWork of a property change in a document. |
||
| 3019 | * |
||
| 3020 | * @param object $document The document that owns the property. |
||
| 3021 | * @param string $propertyName The name of the property that changed. |
||
| 3022 | * @param mixed $oldValue The old value of the property. |
||
| 3023 | * @param mixed $newValue The new value of the property. |
||
| 3024 | */ |
||
| 3025 | 2 | public function propertyChanged($document, $propertyName, $oldValue, $newValue) |
|
| 3040 | |||
| 3041 | /** |
||
| 3042 | * Gets the currently scheduled document insertions in this UnitOfWork. |
||
| 3043 | * |
||
| 3044 | * @return array |
||
| 3045 | */ |
||
| 3046 | 5 | public function getScheduledDocumentInsertions() |
|
| 3050 | |||
| 3051 | /** |
||
| 3052 | * Gets the currently scheduled document upserts in this UnitOfWork. |
||
| 3053 | * |
||
| 3054 | * @return array |
||
| 3055 | */ |
||
| 3056 | 3 | public function getScheduledDocumentUpserts() |
|
| 3060 | |||
| 3061 | /** |
||
| 3062 | * Gets the currently scheduled document updates in this UnitOfWork. |
||
| 3063 | * |
||
| 3064 | * @return array |
||
| 3065 | */ |
||
| 3066 | 3 | public function getScheduledDocumentUpdates() |
|
| 3070 | |||
| 3071 | /** |
||
| 3072 | * Gets the currently scheduled document deletions in this UnitOfWork. |
||
| 3073 | * |
||
| 3074 | * @return array |
||
| 3075 | */ |
||
| 3076 | public function getScheduledDocumentDeletions() |
||
| 3080 | |||
| 3081 | /** |
||
| 3082 | * Get the currently scheduled complete collection deletions |
||
| 3083 | * |
||
| 3084 | * @return array |
||
| 3085 | */ |
||
| 3086 | public function getScheduledCollectionDeletions() |
||
| 3090 | |||
| 3091 | /** |
||
| 3092 | * Gets the currently scheduled collection inserts, updates and deletes. |
||
| 3093 | * |
||
| 3094 | * @return array |
||
| 3095 | */ |
||
| 3096 | public function getScheduledCollectionUpdates() |
||
| 3100 | |||
| 3101 | /** |
||
| 3102 | * Helper method to initialize a lazy loading proxy or persistent collection. |
||
| 3103 | * |
||
| 3104 | * @param object |
||
| 3105 | * @return void |
||
| 3106 | */ |
||
| 3107 | public function initializeObject($obj) |
||
| 3115 | |||
| 3116 | 1 | private static function objToStr($obj) |
|
| 3120 | } |
||
| 3121 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.