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 |
||
| 27 | class UnitOfWork implements PropertyChangedListener |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * A document is in MANAGED state when its persistence is managed by a DocumentManager. |
||
| 31 | */ |
||
| 32 | const STATE_MANAGED = 1; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * A document is new if it has just been instantiated (i.e. using the "new" operator) |
||
| 36 | * and is not (yet) managed by a DocumentManager. |
||
| 37 | */ |
||
| 38 | const STATE_NEW = 2; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * A detached document is an instance with a persistent identity that is not |
||
| 42 | * (or no longer) associated with a DocumentManager (and a UnitOfWork). |
||
| 43 | */ |
||
| 44 | const STATE_DETACHED = 3; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * A removed document instance is an instance with a persistent identity, |
||
| 48 | * associated with a DocumentManager, whose persistent state has been |
||
| 49 | * deleted (or is scheduled for deletion). |
||
| 50 | */ |
||
| 51 | const STATE_REMOVED = 4; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * The identity map holds references to all managed documents. |
||
| 55 | * |
||
| 56 | * Documents are grouped by their class name, and then indexed by the |
||
| 57 | * serialized string of their database identifier field or, if the class |
||
| 58 | * has no identifier, the SPL object hash. Serializing the identifier allows |
||
| 59 | * differentiation of values that may be equal (via type juggling) but not |
||
| 60 | * identical. |
||
| 61 | * |
||
| 62 | * Since all classes in a hierarchy must share the same identifier set, |
||
| 63 | * we always take the root class name of the hierarchy. |
||
| 64 | * |
||
| 65 | * @var array |
||
| 66 | */ |
||
| 67 | private $identityMap = array(); |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Map of all identifiers of managed documents. |
||
| 71 | * Keys are object ids (spl_object_hash). |
||
| 72 | * |
||
| 73 | * @var array |
||
| 74 | */ |
||
| 75 | private $documentIdentifiers = array(); |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Map of the original document data of managed documents. |
||
| 79 | * Keys are object ids (spl_object_hash). This is used for calculating changesets |
||
| 80 | * at commit time. |
||
| 81 | * |
||
| 82 | * @var array |
||
| 83 | * @internal Note that PHPs "copy-on-write" behavior helps a lot with memory usage. |
||
| 84 | * A value will only really be copied if the value in the document is modified |
||
| 85 | * by the user. |
||
| 86 | */ |
||
| 87 | private $originalDocumentData = array(); |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Map of document changes. Keys are object ids (spl_object_hash). |
||
| 91 | * Filled at the beginning of a commit of the UnitOfWork and cleaned at the end. |
||
| 92 | * |
||
| 93 | * @var array |
||
| 94 | */ |
||
| 95 | private $documentChangeSets = array(); |
||
| 96 | |||
| 97 | /** |
||
| 98 | * The (cached) states of any known documents. |
||
| 99 | * Keys are object ids (spl_object_hash). |
||
| 100 | * |
||
| 101 | * @var array |
||
| 102 | */ |
||
| 103 | private $documentStates = array(); |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Map of documents that are scheduled for dirty checking at commit time. |
||
| 107 | * |
||
| 108 | * Documents are grouped by their class name, and then indexed by their SPL |
||
| 109 | * object hash. This is only used for documents with a change tracking |
||
| 110 | * policy of DEFERRED_EXPLICIT. |
||
| 111 | * |
||
| 112 | * @var array |
||
| 113 | * @todo rename: scheduledForSynchronization |
||
| 114 | */ |
||
| 115 | private $scheduledForDirtyCheck = array(); |
||
| 116 | |||
| 117 | /** |
||
| 118 | * A list of all pending document insertions. |
||
| 119 | * |
||
| 120 | * @var array |
||
| 121 | */ |
||
| 122 | private $documentInsertions = array(); |
||
| 123 | |||
| 124 | /** |
||
| 125 | * A list of all pending document updates. |
||
| 126 | * |
||
| 127 | * @var array |
||
| 128 | */ |
||
| 129 | private $documentUpdates = array(); |
||
| 130 | |||
| 131 | /** |
||
| 132 | * A list of all pending document upserts. |
||
| 133 | * |
||
| 134 | * @var array |
||
| 135 | */ |
||
| 136 | private $documentUpserts = array(); |
||
| 137 | |||
| 138 | /** |
||
| 139 | * A list of all pending document deletions. |
||
| 140 | * |
||
| 141 | * @var array |
||
| 142 | */ |
||
| 143 | private $documentDeletions = array(); |
||
| 144 | |||
| 145 | /** |
||
| 146 | * All pending collection deletions. |
||
| 147 | * |
||
| 148 | * @var array |
||
| 149 | */ |
||
| 150 | private $collectionDeletions = array(); |
||
| 151 | |||
| 152 | /** |
||
| 153 | * All pending collection updates. |
||
| 154 | * |
||
| 155 | * @var array |
||
| 156 | */ |
||
| 157 | private $collectionUpdates = array(); |
||
| 158 | |||
| 159 | /** |
||
| 160 | * A list of documents related to collections scheduled for update or deletion |
||
| 161 | * |
||
| 162 | * @var array |
||
| 163 | */ |
||
| 164 | private $hasScheduledCollections = array(); |
||
| 165 | |||
| 166 | /** |
||
| 167 | * List of collections visited during changeset calculation on a commit-phase of a UnitOfWork. |
||
| 168 | * At the end of the UnitOfWork all these collections will make new snapshots |
||
| 169 | * of their data. |
||
| 170 | * |
||
| 171 | * @var array |
||
| 172 | */ |
||
| 173 | private $visitedCollections = array(); |
||
| 174 | |||
| 175 | /** |
||
| 176 | * The DocumentManager that "owns" this UnitOfWork instance. |
||
| 177 | * |
||
| 178 | * @var DocumentManager |
||
| 179 | */ |
||
| 180 | private $dm; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * The EventManager used for dispatching events. |
||
| 184 | * |
||
| 185 | * @var EventManager |
||
| 186 | */ |
||
| 187 | private $evm; |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Additional documents that are scheduled for removal. |
||
| 191 | * |
||
| 192 | * @var array |
||
| 193 | */ |
||
| 194 | private $orphanRemovals = array(); |
||
| 195 | |||
| 196 | /** |
||
| 197 | * The HydratorFactory used for hydrating array Mongo documents to Doctrine object documents. |
||
| 198 | * |
||
| 199 | * @var HydratorFactory |
||
| 200 | */ |
||
| 201 | private $hydratorFactory; |
||
| 202 | |||
| 203 | /** |
||
| 204 | * The document persister instances used to persist document instances. |
||
| 205 | * |
||
| 206 | * @var array |
||
| 207 | */ |
||
| 208 | private $persisters = array(); |
||
| 209 | |||
| 210 | /** |
||
| 211 | * The collection persister instance used to persist changes to collections. |
||
| 212 | * |
||
| 213 | * @var Persisters\CollectionPersister |
||
| 214 | */ |
||
| 215 | private $collectionPersister; |
||
| 216 | |||
| 217 | /** |
||
| 218 | * The persistence builder instance used in DocumentPersisters. |
||
| 219 | * |
||
| 220 | * @var PersistenceBuilder |
||
| 221 | */ |
||
| 222 | private $persistenceBuilder; |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Array of parent associations between embedded documents. |
||
| 226 | * |
||
| 227 | * @var array |
||
| 228 | */ |
||
| 229 | private $parentAssociations = array(); |
||
| 230 | |||
| 231 | /** |
||
| 232 | * @var LifecycleEventManager |
||
| 233 | */ |
||
| 234 | private $lifecycleEventManager; |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Array of embedded documents known to UnitOfWork. We need to hold them to prevent spl_object_hash |
||
| 238 | * collisions in case already managed object is lost due to GC (so now it won't). Embedded documents |
||
| 239 | * found during doDetach are removed from the registry, to empty it altogether clear() can be utilized. |
||
| 240 | * |
||
| 241 | * @var array |
||
| 242 | */ |
||
| 243 | private $embeddedDocumentsRegistry = array(); |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @var int |
||
| 247 | */ |
||
| 248 | private $commitsInProgress = 0; |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Initializes a new UnitOfWork instance, bound to the given DocumentManager. |
||
| 252 | * |
||
| 253 | * @param DocumentManager $dm |
||
| 254 | * @param EventManager $evm |
||
| 255 | * @param HydratorFactory $hydratorFactory |
||
| 256 | */ |
||
| 257 | 1617 | public function __construct(DocumentManager $dm, EventManager $evm, HydratorFactory $hydratorFactory) |
|
| 264 | |||
| 265 | /** |
||
| 266 | * Factory for returning new PersistenceBuilder instances used for preparing data into |
||
| 267 | * queries for insert persistence. |
||
| 268 | * |
||
| 269 | * @return PersistenceBuilder $pb |
||
| 270 | */ |
||
| 271 | 1077 | public function getPersistenceBuilder() |
|
| 278 | |||
| 279 | /** |
||
| 280 | * Sets the parent association for a given embedded document. |
||
| 281 | * |
||
| 282 | * @param object $document |
||
| 283 | * @param array $mapping |
||
| 284 | * @param object $parent |
||
| 285 | * @param string $propertyPath |
||
| 286 | */ |
||
| 287 | 177 | 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 | 203 | public function getParentAssociation($document) |
|
| 310 | |||
| 311 | /** |
||
| 312 | * Get the document persister instance for the given document name |
||
| 313 | * |
||
| 314 | * @param string $documentName |
||
| 315 | * @return Persisters\DocumentPersister |
||
| 316 | */ |
||
| 317 | 1075 | public function getDocumentPersister($documentName) |
|
| 326 | |||
| 327 | /** |
||
| 328 | * Get the collection persister instance. |
||
| 329 | * |
||
| 330 | * @return \Doctrine\ODM\MongoDB\Persisters\CollectionPersister |
||
| 331 | */ |
||
| 332 | 1075 | public function getCollectionPersister() |
|
| 340 | |||
| 341 | /** |
||
| 342 | * Set the document persister instance to use for the given document name |
||
| 343 | * |
||
| 344 | * @param string $documentName |
||
| 345 | * @param Persisters\DocumentPersister $persister |
||
| 346 | */ |
||
| 347 | 13 | public function setDocumentPersister($documentName, Persisters\DocumentPersister $persister) |
|
| 351 | |||
| 352 | /** |
||
| 353 | * Commits the UnitOfWork, executing all operations that have been postponed |
||
| 354 | * up to this point. The state of all managed documents will be synchronized with |
||
| 355 | * the database. |
||
| 356 | * |
||
| 357 | * The operations are executed in the following order: |
||
| 358 | * |
||
| 359 | * 1) All document insertions |
||
| 360 | * 2) All document updates |
||
| 361 | * 3) All document deletions |
||
| 362 | * |
||
| 363 | * @param array $options Array of options to be used with batchInsert(), update() and remove() |
||
| 364 | */ |
||
| 365 | 567 | public function commit(array $options = array()) |
|
| 443 | |||
| 444 | /** |
||
| 445 | * Groups a list of scheduled documents by their class. |
||
| 446 | * |
||
| 447 | * @param array $documents Scheduled documents (e.g. $this->documentInsertions) |
||
| 448 | * @param bool $includeEmbedded |
||
| 449 | * @return array Tuples of ClassMetadata and a corresponding array of objects |
||
| 450 | */ |
||
| 451 | 562 | private function getClassesForCommitAction($documents, $includeEmbedded = false) |
|
| 480 | |||
| 481 | /** |
||
| 482 | * Compute changesets of all documents scheduled for insertion. |
||
| 483 | * |
||
| 484 | * Embedded documents will not be processed. |
||
| 485 | */ |
||
| 486 | 570 | View Code Duplication | private function computeScheduleInsertsChangeSets() |
| 495 | |||
| 496 | /** |
||
| 497 | * Compute changesets of all documents scheduled for upsert. |
||
| 498 | * |
||
| 499 | * Embedded documents will not be processed. |
||
| 500 | */ |
||
| 501 | 569 | View Code Duplication | private function computeScheduleUpsertsChangeSets() |
| 510 | |||
| 511 | /** |
||
| 512 | * Gets the changeset for a document. |
||
| 513 | * |
||
| 514 | * @param object $document |
||
| 515 | * @return array array('property' => array(0 => mixed|null, 1 => mixed|null)) |
||
| 516 | */ |
||
| 517 | 564 | public function getDocumentChangeSet($document) |
|
| 523 | |||
| 524 | /** |
||
| 525 | * INTERNAL: |
||
| 526 | * Sets the changeset for a document. |
||
| 527 | * |
||
| 528 | * @param object $document |
||
| 529 | * @param array $changeset |
||
| 530 | */ |
||
| 531 | 1 | public function setDocumentChangeSet($document, $changeset) |
|
| 535 | |||
| 536 | /** |
||
| 537 | * Get a documents actual data, flattening all the objects to arrays. |
||
| 538 | * |
||
| 539 | * @param object $document |
||
| 540 | * @return array |
||
| 541 | */ |
||
| 542 | 571 | public function getDocumentActualData($document) |
|
| 572 | |||
| 573 | /** |
||
| 574 | * Computes the changes that happened to a single document. |
||
| 575 | * |
||
| 576 | * Modifies/populates the following properties: |
||
| 577 | * |
||
| 578 | * {@link originalDocumentData} |
||
| 579 | * If the document is NEW or MANAGED but not yet fully persisted (only has an id) |
||
| 580 | * then it was not fetched from the database and therefore we have no original |
||
| 581 | * document data yet. All of the current document data is stored as the original document data. |
||
| 582 | * |
||
| 583 | * {@link documentChangeSets} |
||
| 584 | * The changes detected on all properties of the document are stored there. |
||
| 585 | * A change is a tuple array where the first entry is the old value and the second |
||
| 586 | * entry is the new value of the property. Changesets are used by persisters |
||
| 587 | * to INSERT/UPDATE the persistent document state. |
||
| 588 | * |
||
| 589 | * {@link documentUpdates} |
||
| 590 | * If the document is already fully MANAGED (has been fetched from the database before) |
||
| 591 | * and any changes to its properties are detected, then a reference to the document is stored |
||
| 592 | * there to mark it for an update. |
||
| 593 | * |
||
| 594 | * @param ClassMetadata $class The class descriptor of the document. |
||
| 595 | * @param object $document The document for which to compute the changes. |
||
| 596 | */ |
||
| 597 | 567 | public function computeChangeSet(ClassMetadata $class, $document) |
|
| 610 | |||
| 611 | /** |
||
| 612 | * Used to do the common work of computeChangeSet and recomputeSingleDocumentChangeSet |
||
| 613 | * |
||
| 614 | * @param \Doctrine\ODM\MongoDB\Mapping\ClassMetadata $class |
||
| 615 | * @param object $document |
||
| 616 | * @param boolean $recompute |
||
| 617 | */ |
||
| 618 | 567 | private function computeOrRecomputeChangeSet(ClassMetadata $class, $document, $recompute = false) |
|
| 791 | |||
| 792 | /** |
||
| 793 | * Computes all the changes that have been done to documents and collections |
||
| 794 | * since the last commit and stores these changes in the _documentChangeSet map |
||
| 795 | * temporarily for access by the persisters, until the UoW commit is finished. |
||
| 796 | */ |
||
| 797 | 570 | public function computeChangeSets() |
|
| 847 | |||
| 848 | /** |
||
| 849 | * Computes the changes of an association. |
||
| 850 | * |
||
| 851 | * @param object $parentDocument |
||
| 852 | * @param array $assoc |
||
| 853 | * @param mixed $value The value of the association. |
||
| 854 | * @throws \InvalidArgumentException |
||
| 855 | */ |
||
| 856 | 418 | private function computeAssociationChanges($parentDocument, array $assoc, $value) |
|
| 961 | |||
| 962 | /** |
||
| 963 | * INTERNAL: |
||
| 964 | * Computes the changeset of an individual document, independently of the |
||
| 965 | * computeChangeSets() routine that is used at the beginning of a UnitOfWork#commit(). |
||
| 966 | * |
||
| 967 | * The passed document must be a managed document. If the document already has a change set |
||
| 968 | * because this method is invoked during a commit cycle then the change sets are added. |
||
| 969 | * whereby changes detected in this method prevail. |
||
| 970 | * |
||
| 971 | * @ignore |
||
| 972 | * @param ClassMetadata $class The class descriptor of the document. |
||
| 973 | * @param object $document The document for which to (re)calculate the change set. |
||
| 974 | * @throws \InvalidArgumentException If the passed document is not MANAGED. |
||
| 975 | */ |
||
| 976 | 17 | public function recomputeSingleDocumentChangeSet(ClassMetadata $class, $document) |
|
| 995 | |||
| 996 | /** |
||
| 997 | * @param ClassMetadata $class |
||
| 998 | * @param object $document |
||
| 999 | * @throws \InvalidArgumentException If there is something wrong with document's identifier. |
||
| 1000 | */ |
||
| 1001 | 597 | private function persistNew(ClassMetadata $class, $document) |
|
| 1044 | |||
| 1045 | /** |
||
| 1046 | * Executes all document insertions for documents of the specified type. |
||
| 1047 | * |
||
| 1048 | * @param ClassMetadata $class |
||
| 1049 | * @param array $documents Array of documents to insert |
||
| 1050 | * @param array $options Array of options to be used with batchInsert() |
||
| 1051 | */ |
||
| 1052 | 488 | View Code Duplication | private function executeInserts(ClassMetadata $class, array $documents, array $options = array()) |
| 1067 | |||
| 1068 | /** |
||
| 1069 | * Executes all document upserts for documents of the specified type. |
||
| 1070 | * |
||
| 1071 | * @param ClassMetadata $class |
||
| 1072 | * @param array $documents Array of documents to upsert |
||
| 1073 | * @param array $options Array of options to be used with batchInsert() |
||
| 1074 | */ |
||
| 1075 | 85 | View Code Duplication | private function executeUpserts(ClassMetadata $class, array $documents, array $options = array()) |
| 1091 | |||
| 1092 | /** |
||
| 1093 | * Executes all document updates for documents of the specified type. |
||
| 1094 | * |
||
| 1095 | * @param Mapping\ClassMetadata $class |
||
| 1096 | * @param array $documents Array of documents to update |
||
| 1097 | * @param array $options Array of options to be used with update() |
||
| 1098 | */ |
||
| 1099 | 204 | private function executeUpdates(ClassMetadata $class, array $documents, array $options = array()) |
|
| 1120 | |||
| 1121 | /** |
||
| 1122 | * Executes all document deletions for documents of the specified type. |
||
| 1123 | * |
||
| 1124 | * @param ClassMetadata $class |
||
| 1125 | * @param array $documents Array of documents to delete |
||
| 1126 | * @param array $options Array of options to be used with remove() |
||
| 1127 | */ |
||
| 1128 | 64 | private function executeDeletions(ClassMetadata $class, array $documents, array $options = array()) |
|
| 1160 | |||
| 1161 | /** |
||
| 1162 | * Schedules a document for insertion into the database. |
||
| 1163 | * If the document already has an identifier, it will be added to the |
||
| 1164 | * identity map. |
||
| 1165 | * |
||
| 1166 | * @param ClassMetadata $class |
||
| 1167 | * @param object $document The document to schedule for insertion. |
||
| 1168 | * @throws \InvalidArgumentException |
||
| 1169 | */ |
||
| 1170 | 528 | public function scheduleForInsert(ClassMetadata $class, $document) |
|
| 1190 | |||
| 1191 | /** |
||
| 1192 | * Schedules a document for upsert into the database and adds it to the |
||
| 1193 | * identity map |
||
| 1194 | * |
||
| 1195 | * @param ClassMetadata $class |
||
| 1196 | * @param object $document The document to schedule for upsert. |
||
| 1197 | * @throws \InvalidArgumentException |
||
| 1198 | */ |
||
| 1199 | 91 | public function scheduleForUpsert(ClassMetadata $class, $document) |
|
| 1220 | |||
| 1221 | /** |
||
| 1222 | * Checks whether a document is scheduled for insertion. |
||
| 1223 | * |
||
| 1224 | * @param object $document |
||
| 1225 | * @return boolean |
||
| 1226 | */ |
||
| 1227 | 89 | public function isScheduledForInsert($document) |
|
| 1231 | |||
| 1232 | /** |
||
| 1233 | * Checks whether a document is scheduled for upsert. |
||
| 1234 | * |
||
| 1235 | * @param object $document |
||
| 1236 | * @return boolean |
||
| 1237 | */ |
||
| 1238 | 5 | public function isScheduledForUpsert($document) |
|
| 1242 | |||
| 1243 | /** |
||
| 1244 | * Schedules a document for being updated. |
||
| 1245 | * |
||
| 1246 | * @param object $document The document to schedule for being updated. |
||
| 1247 | * @throws \InvalidArgumentException |
||
| 1248 | */ |
||
| 1249 | 210 | public function scheduleForUpdate($document) |
|
| 1266 | |||
| 1267 | /** |
||
| 1268 | * Checks whether a document is registered as dirty in the unit of work. |
||
| 1269 | * Note: Is not very useful currently as dirty documents are only registered |
||
| 1270 | * at commit time. |
||
| 1271 | * |
||
| 1272 | * @param object $document |
||
| 1273 | * @return boolean |
||
| 1274 | */ |
||
| 1275 | 15 | public function isScheduledForUpdate($document) |
|
| 1279 | |||
| 1280 | 1 | public function isScheduledForDirtyCheck($document) |
|
| 1285 | |||
| 1286 | /** |
||
| 1287 | * INTERNAL: |
||
| 1288 | * Schedules a document for deletion. |
||
| 1289 | * |
||
| 1290 | * @param object $document |
||
| 1291 | */ |
||
| 1292 | 69 | public function scheduleForDelete($document) |
|
| 1318 | |||
| 1319 | /** |
||
| 1320 | * Checks whether a document is registered as removed/deleted with the unit |
||
| 1321 | * of work. |
||
| 1322 | * |
||
| 1323 | * @param object $document |
||
| 1324 | * @return boolean |
||
| 1325 | */ |
||
| 1326 | 5 | public function isScheduledForDelete($document) |
|
| 1330 | |||
| 1331 | /** |
||
| 1332 | * Checks whether a document is scheduled for insertion, update or deletion. |
||
| 1333 | * |
||
| 1334 | * @param $document |
||
| 1335 | * @return boolean |
||
| 1336 | */ |
||
| 1337 | 226 | public function isDocumentScheduled($document) |
|
| 1345 | |||
| 1346 | /** |
||
| 1347 | * INTERNAL: |
||
| 1348 | * Registers a document in the identity map. |
||
| 1349 | * |
||
| 1350 | * Note that documents in a hierarchy are registered with the class name of |
||
| 1351 | * the root document. Identifiers are serialized before being used as array |
||
| 1352 | * keys to allow differentiation of equal, but not identical, values. |
||
| 1353 | * |
||
| 1354 | * @ignore |
||
| 1355 | * @param object $document The document to register. |
||
| 1356 | * @return boolean TRUE if the registration was successful, FALSE if the identity of |
||
| 1357 | * the document in question is already managed. |
||
| 1358 | */ |
||
| 1359 | 627 | public function addToIdentityMap($document) |
|
| 1377 | |||
| 1378 | /** |
||
| 1379 | * Gets the state of a document with regard to the current unit of work. |
||
| 1380 | * |
||
| 1381 | * @param object $document |
||
| 1382 | * @param int|null $assume The state to assume if the state is not yet known (not MANAGED or REMOVED). |
||
| 1383 | * This parameter can be set to improve performance of document state detection |
||
| 1384 | * by potentially avoiding a database lookup if the distinction between NEW and DETACHED |
||
| 1385 | * is either known or does not matter for the caller of the method. |
||
| 1386 | * @return int The document state. |
||
| 1387 | */ |
||
| 1388 | 599 | public function getDocumentState($document, $assume = null) |
|
| 1438 | |||
| 1439 | /** |
||
| 1440 | * INTERNAL: |
||
| 1441 | * Removes a document from the identity map. This effectively detaches the |
||
| 1442 | * document from the persistence management of Doctrine. |
||
| 1443 | * |
||
| 1444 | * @ignore |
||
| 1445 | * @param object $document |
||
| 1446 | * @throws \InvalidArgumentException |
||
| 1447 | * @return boolean |
||
| 1448 | */ |
||
| 1449 | 81 | public function removeFromIdentityMap($document) |
|
| 1469 | |||
| 1470 | /** |
||
| 1471 | * INTERNAL: |
||
| 1472 | * Gets a document in the identity map by its identifier hash. |
||
| 1473 | * |
||
| 1474 | * @ignore |
||
| 1475 | * @param mixed $id Document identifier |
||
| 1476 | * @param ClassMetadata $class Document class |
||
| 1477 | * @return object |
||
| 1478 | * @throws InvalidArgumentException if the class does not have an identifier |
||
| 1479 | */ |
||
| 1480 | 38 | View Code Duplication | public function getById($id, ClassMetadata $class) |
| 1490 | |||
| 1491 | /** |
||
| 1492 | * INTERNAL: |
||
| 1493 | * Tries to get a document by its identifier hash. If no document is found |
||
| 1494 | * for the given hash, FALSE is returned. |
||
| 1495 | * |
||
| 1496 | * @ignore |
||
| 1497 | * @param mixed $id Document identifier |
||
| 1498 | * @param ClassMetadata $class Document class |
||
| 1499 | * @return mixed The found document or FALSE. |
||
| 1500 | * @throws InvalidArgumentException if the class does not have an identifier |
||
| 1501 | */ |
||
| 1502 | 293 | View Code Duplication | public function tryGetById($id, ClassMetadata $class) |
| 1512 | |||
| 1513 | /** |
||
| 1514 | * Schedules a document for dirty-checking at commit-time. |
||
| 1515 | * |
||
| 1516 | * @param object $document The document to schedule for dirty-checking. |
||
| 1517 | * @todo Rename: scheduleForSynchronization |
||
| 1518 | */ |
||
| 1519 | 3 | public function scheduleForDirtyCheck($document) |
|
| 1524 | |||
| 1525 | /** |
||
| 1526 | * Checks whether a document is registered in the identity map. |
||
| 1527 | * |
||
| 1528 | * @param object $document |
||
| 1529 | * @return boolean |
||
| 1530 | */ |
||
| 1531 | 77 | public function isInIdentityMap($document) |
|
| 1544 | |||
| 1545 | /** |
||
| 1546 | * @param object $document |
||
| 1547 | * @return string |
||
| 1548 | */ |
||
| 1549 | 627 | private function getIdForIdentityMap($document) |
|
| 1562 | |||
| 1563 | /** |
||
| 1564 | * INTERNAL: |
||
| 1565 | * Checks whether an identifier exists in the identity map. |
||
| 1566 | * |
||
| 1567 | * @ignore |
||
| 1568 | * @param string $id |
||
| 1569 | * @param string $rootClassName |
||
| 1570 | * @return boolean |
||
| 1571 | */ |
||
| 1572 | public function containsId($id, $rootClassName) |
||
| 1576 | |||
| 1577 | /** |
||
| 1578 | * Persists a document as part of the current unit of work. |
||
| 1579 | * |
||
| 1580 | * @param object $document The document to persist. |
||
| 1581 | * @throws MongoDBException If trying to persist MappedSuperclass. |
||
| 1582 | * @throws \InvalidArgumentException If there is something wrong with document's identifier. |
||
| 1583 | */ |
||
| 1584 | 597 | public function persist($document) |
|
| 1593 | |||
| 1594 | /** |
||
| 1595 | * Saves a document as part of the current unit of work. |
||
| 1596 | * This method is internally called during save() cascades as it tracks |
||
| 1597 | * the already visited documents to prevent infinite recursions. |
||
| 1598 | * |
||
| 1599 | * NOTE: This method always considers documents that are not yet known to |
||
| 1600 | * this UnitOfWork as NEW. |
||
| 1601 | * |
||
| 1602 | * @param object $document The document to persist. |
||
| 1603 | * @param array $visited The already visited documents. |
||
| 1604 | * @throws \InvalidArgumentException |
||
| 1605 | * @throws MongoDBException |
||
| 1606 | */ |
||
| 1607 | 596 | private function doPersist($document, array &$visited) |
|
| 1647 | |||
| 1648 | /** |
||
| 1649 | * Deletes a document as part of the current unit of work. |
||
| 1650 | * |
||
| 1651 | * @param object $document The document to remove. |
||
| 1652 | */ |
||
| 1653 | 68 | public function remove($document) |
|
| 1658 | |||
| 1659 | /** |
||
| 1660 | * Deletes a document as part of the current unit of work. |
||
| 1661 | * |
||
| 1662 | * This method is internally called during delete() cascades as it tracks |
||
| 1663 | * the already visited documents to prevent infinite recursions. |
||
| 1664 | * |
||
| 1665 | * @param object $document The document to delete. |
||
| 1666 | * @param array $visited The map of the already visited documents. |
||
| 1667 | * @throws MongoDBException |
||
| 1668 | */ |
||
| 1669 | 68 | private function doRemove($document, array &$visited) |
|
| 1701 | |||
| 1702 | /** |
||
| 1703 | * Merges the state of the given detached document into this UnitOfWork. |
||
| 1704 | * |
||
| 1705 | * @param object $document |
||
| 1706 | * @return object The managed copy of the document. |
||
| 1707 | */ |
||
| 1708 | 12 | public function merge($document) |
|
| 1714 | |||
| 1715 | /** |
||
| 1716 | * Executes a merge operation on a document. |
||
| 1717 | * |
||
| 1718 | * @param object $document |
||
| 1719 | * @param array $visited |
||
| 1720 | * @param object|null $prevManagedCopy |
||
| 1721 | * @param array|null $assoc |
||
| 1722 | * |
||
| 1723 | * @return object The managed copy of the document. |
||
| 1724 | * |
||
| 1725 | * @throws InvalidArgumentException If the entity instance is NEW. |
||
| 1726 | * @throws LockException If the document uses optimistic locking through a |
||
| 1727 | * version attribute and the version check against the |
||
| 1728 | * managed copy fails. |
||
| 1729 | */ |
||
| 1730 | 12 | private function doMerge($document, array &$visited, $prevManagedCopy = null, $assoc = null) |
|
| 1904 | |||
| 1905 | /** |
||
| 1906 | * Detaches a document from the persistence management. It's persistence will |
||
| 1907 | * no longer be managed by Doctrine. |
||
| 1908 | * |
||
| 1909 | * @param object $document The document to detach. |
||
| 1910 | */ |
||
| 1911 | 11 | public function detach($document) |
|
| 1916 | |||
| 1917 | /** |
||
| 1918 | * Executes a detach operation on the given document. |
||
| 1919 | * |
||
| 1920 | * @param object $document |
||
| 1921 | * @param array $visited |
||
| 1922 | * @internal This method always considers documents with an assigned identifier as DETACHED. |
||
| 1923 | */ |
||
| 1924 | 16 | private function doDetach($document, array &$visited) |
|
| 1949 | |||
| 1950 | /** |
||
| 1951 | * Refreshes the state of the given document from the database, overwriting |
||
| 1952 | * any local, unpersisted changes. |
||
| 1953 | * |
||
| 1954 | * @param object $document The document to refresh. |
||
| 1955 | * @throws \InvalidArgumentException If the document is not MANAGED. |
||
| 1956 | */ |
||
| 1957 | 21 | public function refresh($document) |
|
| 1962 | |||
| 1963 | /** |
||
| 1964 | * Executes a refresh operation on a document. |
||
| 1965 | * |
||
| 1966 | * @param object $document The document to refresh. |
||
| 1967 | * @param array $visited The already visited documents during cascades. |
||
| 1968 | * @throws \InvalidArgumentException If the document is not MANAGED. |
||
| 1969 | */ |
||
| 1970 | 21 | private function doRefresh($document, array &$visited) |
|
| 1991 | |||
| 1992 | /** |
||
| 1993 | * Cascades a refresh operation to associated documents. |
||
| 1994 | * |
||
| 1995 | * @param object $document |
||
| 1996 | * @param array $visited |
||
| 1997 | */ |
||
| 1998 | 20 | private function cascadeRefresh($document, array &$visited) |
|
| 2022 | |||
| 2023 | /** |
||
| 2024 | * Cascades a detach operation to associated documents. |
||
| 2025 | * |
||
| 2026 | * @param object $document |
||
| 2027 | * @param array $visited |
||
| 2028 | */ |
||
| 2029 | 16 | View Code Duplication | private function cascadeDetach($document, array &$visited) |
| 2050 | /** |
||
| 2051 | * Cascades a merge operation to associated documents. |
||
| 2052 | * |
||
| 2053 | * @param object $document |
||
| 2054 | * @param object $managedCopy |
||
| 2055 | * @param array $visited |
||
| 2056 | */ |
||
| 2057 | 12 | private function cascadeMerge($document, $managedCopy, array &$visited) |
|
| 2083 | |||
| 2084 | /** |
||
| 2085 | * Cascades the save operation to associated documents. |
||
| 2086 | * |
||
| 2087 | * @param object $document |
||
| 2088 | * @param array $visited |
||
| 2089 | */ |
||
| 2090 | 594 | private function cascadePersist($document, array &$visited) |
|
| 2137 | |||
| 2138 | /** |
||
| 2139 | * Cascades the delete operation to associated documents. |
||
| 2140 | * |
||
| 2141 | * @param object $document |
||
| 2142 | * @param array $visited |
||
| 2143 | */ |
||
| 2144 | 68 | View Code Duplication | private function cascadeRemove($document, array &$visited) |
| 2166 | |||
| 2167 | /** |
||
| 2168 | * Acquire a lock on the given document. |
||
| 2169 | * |
||
| 2170 | * @param object $document |
||
| 2171 | * @param int $lockMode |
||
| 2172 | * @param int $lockVersion |
||
| 2173 | * @throws LockException |
||
| 2174 | * @throws \InvalidArgumentException |
||
| 2175 | */ |
||
| 2176 | 8 | public function lock($document, $lockMode, $lockVersion = null) |
|
| 2200 | |||
| 2201 | /** |
||
| 2202 | * Releases a lock on the given document. |
||
| 2203 | * |
||
| 2204 | * @param object $document |
||
| 2205 | * @throws \InvalidArgumentException |
||
| 2206 | */ |
||
| 2207 | 1 | public function unlock($document) |
|
| 2215 | |||
| 2216 | /** |
||
| 2217 | * Clears the UnitOfWork. |
||
| 2218 | * |
||
| 2219 | * @param string|null $documentName if given, only documents of this type will get detached. |
||
| 2220 | */ |
||
| 2221 | 372 | public function clear($documentName = null) |
|
| 2255 | |||
| 2256 | /** |
||
| 2257 | * INTERNAL: |
||
| 2258 | * Schedules an embedded document for removal. The remove() operation will be |
||
| 2259 | * invoked on that document at the beginning of the next commit of this |
||
| 2260 | * UnitOfWork. |
||
| 2261 | * |
||
| 2262 | * @ignore |
||
| 2263 | * @param object $document |
||
| 2264 | */ |
||
| 2265 | 47 | public function scheduleOrphanRemoval($document) |
|
| 2269 | |||
| 2270 | /** |
||
| 2271 | * INTERNAL: |
||
| 2272 | * Unschedules an embedded or referenced object for removal. |
||
| 2273 | * |
||
| 2274 | * @ignore |
||
| 2275 | * @param object $document |
||
| 2276 | */ |
||
| 2277 | 100 | public function unscheduleOrphanRemoval($document) |
|
| 2284 | |||
| 2285 | /** |
||
| 2286 | * Fixes PersistentCollection state if it wasn't used exactly as we had in mind: |
||
| 2287 | * 1) sets owner if it was cloned |
||
| 2288 | * 2) clones collection, sets owner, updates document's property and, if necessary, updates originalData |
||
| 2289 | * 3) NOP if state is OK |
||
| 2290 | * Returned collection should be used from now on (only important with 2nd point) |
||
| 2291 | * |
||
| 2292 | * @param PersistentCollectionInterface $coll |
||
| 2293 | * @param object $document |
||
| 2294 | * @param ClassMetadata $class |
||
| 2295 | * @param string $propName |
||
| 2296 | * @return PersistentCollectionInterface |
||
| 2297 | */ |
||
| 2298 | 8 | private function fixPersistentCollectionOwnership(PersistentCollectionInterface $coll, $document, ClassMetadata $class, $propName) |
|
| 2318 | |||
| 2319 | /** |
||
| 2320 | * INTERNAL: |
||
| 2321 | * Schedules a complete collection for removal when this UnitOfWork commits. |
||
| 2322 | * |
||
| 2323 | * @param PersistentCollectionInterface $coll |
||
| 2324 | */ |
||
| 2325 | 35 | public function scheduleCollectionDeletion(PersistentCollectionInterface $coll) |
|
| 2334 | |||
| 2335 | /** |
||
| 2336 | * Checks whether a PersistentCollection is scheduled for deletion. |
||
| 2337 | * |
||
| 2338 | * @param PersistentCollectionInterface $coll |
||
| 2339 | * @return boolean |
||
| 2340 | */ |
||
| 2341 | 190 | public function isCollectionScheduledForDeletion(PersistentCollectionInterface $coll) |
|
| 2345 | |||
| 2346 | /** |
||
| 2347 | * INTERNAL: |
||
| 2348 | * Unschedules a collection from being deleted when this UnitOfWork commits. |
||
| 2349 | * |
||
| 2350 | * @param PersistentCollectionInterface $coll |
||
| 2351 | */ |
||
| 2352 | 202 | View Code Duplication | public function unscheduleCollectionDeletion(PersistentCollectionInterface $coll) |
| 2361 | |||
| 2362 | /** |
||
| 2363 | * INTERNAL: |
||
| 2364 | * Schedules a collection for update when this UnitOfWork commits. |
||
| 2365 | * |
||
| 2366 | * @param PersistentCollectionInterface $coll |
||
| 2367 | */ |
||
| 2368 | 223 | public function scheduleCollectionUpdate(PersistentCollectionInterface $coll) |
|
| 2383 | |||
| 2384 | /** |
||
| 2385 | * INTERNAL: |
||
| 2386 | * Unschedules a collection from being updated when this UnitOfWork commits. |
||
| 2387 | * |
||
| 2388 | * @param PersistentCollectionInterface $coll |
||
| 2389 | */ |
||
| 2390 | 202 | View Code Duplication | public function unscheduleCollectionUpdate(PersistentCollectionInterface $coll) |
| 2399 | |||
| 2400 | /** |
||
| 2401 | * Checks whether a PersistentCollection is scheduled for update. |
||
| 2402 | * |
||
| 2403 | * @param PersistentCollectionInterface $coll |
||
| 2404 | * @return boolean |
||
| 2405 | */ |
||
| 2406 | 113 | public function isCollectionScheduledForUpdate(PersistentCollectionInterface $coll) |
|
| 2410 | |||
| 2411 | /** |
||
| 2412 | * INTERNAL: |
||
| 2413 | * Gets PersistentCollections that have been visited during computing change |
||
| 2414 | * set of $document |
||
| 2415 | * |
||
| 2416 | * @param object $document |
||
| 2417 | * @return PersistentCollectionInterface[] |
||
| 2418 | */ |
||
| 2419 | 548 | public function getVisitedCollections($document) |
|
| 2425 | |||
| 2426 | /** |
||
| 2427 | * INTERNAL: |
||
| 2428 | * Gets PersistentCollections that are scheduled to update and related to $document |
||
| 2429 | * |
||
| 2430 | * @param object $document |
||
| 2431 | * @return array |
||
| 2432 | */ |
||
| 2433 | 548 | public function getScheduledCollections($document) |
|
| 2439 | |||
| 2440 | /** |
||
| 2441 | * Checks whether the document is related to a PersistentCollection |
||
| 2442 | * scheduled for update or deletion. |
||
| 2443 | * |
||
| 2444 | * @param object $document |
||
| 2445 | * @return boolean |
||
| 2446 | */ |
||
| 2447 | 44 | public function hasScheduledCollections($document) |
|
| 2451 | |||
| 2452 | /** |
||
| 2453 | * Marks the PersistentCollection's top-level owner as having a relation to |
||
| 2454 | * a collection scheduled for update or deletion. |
||
| 2455 | * |
||
| 2456 | * If the owner is not scheduled for any lifecycle action, it will be |
||
| 2457 | * scheduled for update to ensure that versioning takes place if necessary. |
||
| 2458 | * |
||
| 2459 | * If the collection is nested within atomic collection, it is immediately |
||
| 2460 | * unscheduled and atomic one is scheduled for update instead. This makes |
||
| 2461 | * calculating update data way easier. |
||
| 2462 | * |
||
| 2463 | * @param PersistentCollectionInterface $coll |
||
| 2464 | */ |
||
| 2465 | 225 | private function scheduleCollectionOwner(PersistentCollectionInterface $coll) |
|
| 2488 | |||
| 2489 | /** |
||
| 2490 | * Get the top-most owning document of a given document |
||
| 2491 | * |
||
| 2492 | * If a top-level document is provided, that same document will be returned. |
||
| 2493 | * For an embedded document, we will walk through parent associations until |
||
| 2494 | * we find a top-level document. |
||
| 2495 | * |
||
| 2496 | * @param object $document |
||
| 2497 | * @throws \UnexpectedValueException when a top-level document could not be found |
||
| 2498 | * @return object |
||
| 2499 | */ |
||
| 2500 | 227 | public function getOwningDocument($document) |
|
| 2516 | |||
| 2517 | /** |
||
| 2518 | * Gets the class name for an association (embed or reference) with respect |
||
| 2519 | * to any discriminator value. |
||
| 2520 | * |
||
| 2521 | * @param array $mapping Field mapping for the association |
||
| 2522 | * @param array|null $data Data for the embedded document or reference |
||
| 2523 | * @return string Class name. |
||
| 2524 | */ |
||
| 2525 | 217 | public function getClassNameForAssociation(array $mapping, $data) |
|
| 2555 | |||
| 2556 | /** |
||
| 2557 | * INTERNAL: |
||
| 2558 | * Creates a document. Used for reconstitution of documents during hydration. |
||
| 2559 | * |
||
| 2560 | * @ignore |
||
| 2561 | * @param string $className The name of the document class. |
||
| 2562 | * @param array $data The data for the document. |
||
| 2563 | * @param array $hints Any hints to account for during reconstitution/lookup of the document. |
||
| 2564 | * @param object $document The document to be hydrated into in case of creation |
||
| 2565 | * @return object The document instance. |
||
| 2566 | * @internal Highly performance-sensitive method. |
||
| 2567 | */ |
||
| 2568 | 380 | public function getOrCreateDocument($className, $data, &$hints = array(), $document = null) |
|
| 2638 | |||
| 2639 | /** |
||
| 2640 | * Initializes (loads) an uninitialized persistent collection of a document. |
||
| 2641 | * |
||
| 2642 | * @param PersistentCollectionInterface $collection The collection to initialize. |
||
| 2643 | */ |
||
| 2644 | 163 | public function loadCollection(PersistentCollectionInterface $collection) |
|
| 2649 | |||
| 2650 | /** |
||
| 2651 | * Gets the identity map of the UnitOfWork. |
||
| 2652 | * |
||
| 2653 | * @return array |
||
| 2654 | */ |
||
| 2655 | public function getIdentityMap() |
||
| 2659 | |||
| 2660 | /** |
||
| 2661 | * Gets the original data of a document. The original data is the data that was |
||
| 2662 | * present at the time the document was reconstituted from the database. |
||
| 2663 | * |
||
| 2664 | * @param object $document |
||
| 2665 | * @return array |
||
| 2666 | */ |
||
| 2667 | 1 | public function getOriginalDocumentData($document) |
|
| 2673 | |||
| 2674 | /** |
||
| 2675 | * @ignore |
||
| 2676 | */ |
||
| 2677 | 58 | public function setOriginalDocumentData($document, array $data) |
|
| 2683 | |||
| 2684 | /** |
||
| 2685 | * INTERNAL: |
||
| 2686 | * Sets a property value of the original data array of a document. |
||
| 2687 | * |
||
| 2688 | * @ignore |
||
| 2689 | * @param string $oid |
||
| 2690 | * @param string $property |
||
| 2691 | * @param mixed $value |
||
| 2692 | */ |
||
| 2693 | 3 | public function setOriginalDocumentProperty($oid, $property, $value) |
|
| 2697 | |||
| 2698 | /** |
||
| 2699 | * Gets the identifier of a document. |
||
| 2700 | * |
||
| 2701 | * @param object $document |
||
| 2702 | * @return mixed The identifier value |
||
| 2703 | */ |
||
| 2704 | 411 | public function getDocumentIdentifier($document) |
|
| 2708 | |||
| 2709 | /** |
||
| 2710 | * Checks whether the UnitOfWork has any pending insertions. |
||
| 2711 | * |
||
| 2712 | * @return boolean TRUE if this UnitOfWork has pending insertions, FALSE otherwise. |
||
| 2713 | */ |
||
| 2714 | public function hasPendingInsertions() |
||
| 2718 | |||
| 2719 | /** |
||
| 2720 | * Calculates the size of the UnitOfWork. The size of the UnitOfWork is the |
||
| 2721 | * number of documents in the identity map. |
||
| 2722 | * |
||
| 2723 | * @return integer |
||
| 2724 | */ |
||
| 2725 | 2 | public function size() |
|
| 2733 | |||
| 2734 | /** |
||
| 2735 | * INTERNAL: |
||
| 2736 | * Registers a document as managed. |
||
| 2737 | * |
||
| 2738 | * TODO: This method assumes that $id is a valid PHP identifier for the |
||
| 2739 | * document class. If the class expects its database identifier to be an |
||
| 2740 | * ObjectId, and an incompatible $id is registered (e.g. an integer), the |
||
| 2741 | * document identifiers map will become inconsistent with the identity map. |
||
| 2742 | * In the future, we may want to round-trip $id through a PHP and database |
||
| 2743 | * conversion and throw an exception if it's inconsistent. |
||
| 2744 | * |
||
| 2745 | * @param object $document The document. |
||
| 2746 | * @param array $id The identifier values. |
||
| 2747 | * @param array $data The original document data. |
||
| 2748 | */ |
||
| 2749 | 362 | public function registerManaged($document, $id, $data) |
|
| 2764 | |||
| 2765 | /** |
||
| 2766 | * INTERNAL: |
||
| 2767 | * Clears the property changeset of the document with the given OID. |
||
| 2768 | * |
||
| 2769 | * @param string $oid The document's OID. |
||
| 2770 | */ |
||
| 2771 | public function clearDocumentChangeSet($oid) |
||
| 2775 | |||
| 2776 | /* PropertyChangedListener implementation */ |
||
| 2777 | |||
| 2778 | /** |
||
| 2779 | * Notifies this UnitOfWork of a property change in a document. |
||
| 2780 | * |
||
| 2781 | * @param object $document The document that owns the property. |
||
| 2782 | * @param string $propertyName The name of the property that changed. |
||
| 2783 | * @param mixed $oldValue The old value of the property. |
||
| 2784 | * @param mixed $newValue The new value of the property. |
||
| 2785 | */ |
||
| 2786 | 2 | public function propertyChanged($document, $propertyName, $oldValue, $newValue) |
|
| 2801 | |||
| 2802 | /** |
||
| 2803 | * Gets the currently scheduled document insertions in this UnitOfWork. |
||
| 2804 | * |
||
| 2805 | * @return array |
||
| 2806 | */ |
||
| 2807 | 2 | public function getScheduledDocumentInsertions() |
|
| 2811 | |||
| 2812 | /** |
||
| 2813 | * Gets the currently scheduled document upserts in this UnitOfWork. |
||
| 2814 | * |
||
| 2815 | * @return array |
||
| 2816 | */ |
||
| 2817 | 1 | public function getScheduledDocumentUpserts() |
|
| 2821 | |||
| 2822 | /** |
||
| 2823 | * Gets the currently scheduled document updates in this UnitOfWork. |
||
| 2824 | * |
||
| 2825 | * @return array |
||
| 2826 | */ |
||
| 2827 | 1 | public function getScheduledDocumentUpdates() |
|
| 2831 | |||
| 2832 | /** |
||
| 2833 | * Gets the currently scheduled document deletions in this UnitOfWork. |
||
| 2834 | * |
||
| 2835 | * @return array |
||
| 2836 | */ |
||
| 2837 | public function getScheduledDocumentDeletions() |
||
| 2841 | |||
| 2842 | /** |
||
| 2843 | * Get the currently scheduled complete collection deletions |
||
| 2844 | * |
||
| 2845 | * @return array |
||
| 2846 | */ |
||
| 2847 | public function getScheduledCollectionDeletions() |
||
| 2851 | |||
| 2852 | /** |
||
| 2853 | * Gets the currently scheduled collection inserts, updates and deletes. |
||
| 2854 | * |
||
| 2855 | * @return array |
||
| 2856 | */ |
||
| 2857 | public function getScheduledCollectionUpdates() |
||
| 2861 | |||
| 2862 | /** |
||
| 2863 | * Helper method to initialize a lazy loading proxy or persistent collection. |
||
| 2864 | * |
||
| 2865 | * @param object |
||
| 2866 | * @return void |
||
| 2867 | */ |
||
| 2868 | public function initializeObject($obj) |
||
| 2876 | |||
| 2877 | private function objToStr($obj) |
||
| 2881 | } |
||
| 2882 |
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.