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 |
||
| 58 | class UnitOfWork implements PropertyChangedListener |
||
| 59 | { |
||
| 60 | /** |
||
| 61 | * An entity is in MANAGED state when its persistence is managed by an EntityManager. |
||
| 62 | */ |
||
| 63 | const STATE_MANAGED = 1; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * An entity is new if it has just been instantiated (i.e. using the "new" operator) |
||
| 67 | * and is not (yet) managed by an EntityManager. |
||
| 68 | */ |
||
| 69 | const STATE_NEW = 2; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * A detached entity is an instance with persistent state and identity that is not |
||
| 73 | * (or no longer) associated with an EntityManager (and a UnitOfWork). |
||
| 74 | */ |
||
| 75 | const STATE_DETACHED = 3; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * A removed entity instance is an instance with a persistent identity, |
||
| 79 | * associated with an EntityManager, whose persistent state will be deleted |
||
| 80 | * on commit. |
||
| 81 | */ |
||
| 82 | const STATE_REMOVED = 4; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Hint used to collect all primary keys of associated entities during hydration |
||
| 86 | * and execute it in a dedicated query afterwards |
||
| 87 | * @see https://doctrine-orm.readthedocs.org/en/latest/reference/dql-doctrine-query-language.html?highlight=eager#temporarily-change-fetch-mode-in-dql |
||
| 88 | */ |
||
| 89 | const HINT_DEFEREAGERLOAD = 'deferEagerLoad'; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * The identity map that holds references to all managed entities that have |
||
| 93 | * an identity. The entities are grouped by their class name. |
||
| 94 | * Since all classes in a hierarchy must share the same identifier set, |
||
| 95 | * we always take the root class name of the hierarchy. |
||
| 96 | * |
||
| 97 | * @var array |
||
| 98 | */ |
||
| 99 | private $identityMap = []; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Map of all identifiers of managed entities. |
||
| 103 | * This is a 2-dimensional data structure (map of maps). Keys are object ids (spl_object_hash). |
||
| 104 | * Values are maps of entity identifiers, where its key is the column name and the value is the raw value. |
||
| 105 | * |
||
| 106 | * @var array |
||
| 107 | */ |
||
| 108 | private $entityIdentifiers = []; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Map of the original entity data of managed entities. |
||
| 112 | * This is a 2-dimensional data structure (map of maps). Keys are object ids (spl_object_hash). |
||
| 113 | * Values are maps of entity data, where its key is the field name and the value is the converted |
||
| 114 | * (convertToPHPValue) value. |
||
| 115 | * This structure is used for calculating changesets at commit time. |
||
| 116 | * |
||
| 117 | * Internal: Note that PHPs "copy-on-write" behavior helps a lot with memory usage. |
||
| 118 | * A value will only really be copied if the value in the entity is modified by the user. |
||
| 119 | * |
||
| 120 | * @var array |
||
| 121 | */ |
||
| 122 | private $originalEntityData = []; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Map of entity changes. Keys are object ids (spl_object_hash). |
||
| 126 | * Filled at the beginning of a commit of the UnitOfWork and cleaned at the end. |
||
| 127 | * |
||
| 128 | * @var array |
||
| 129 | */ |
||
| 130 | private $entityChangeSets = []; |
||
| 131 | |||
| 132 | /** |
||
| 133 | * The (cached) states of any known entities. |
||
| 134 | * Keys are object ids (spl_object_hash). |
||
| 135 | * |
||
| 136 | * @var array |
||
| 137 | */ |
||
| 138 | private $entityStates = []; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Map of entities that are scheduled for dirty checking at commit time. |
||
| 142 | * This is only used for entities with a change tracking policy of DEFERRED_EXPLICIT. |
||
| 143 | * Keys are object ids (spl_object_hash). |
||
| 144 | * |
||
| 145 | * @var array |
||
| 146 | */ |
||
| 147 | private $scheduledForSynchronization = []; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * A list of all pending entity insertions. |
||
| 151 | * |
||
| 152 | * @var array |
||
| 153 | */ |
||
| 154 | private $entityInsertions = []; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * A list of all pending entity updates. |
||
| 158 | * |
||
| 159 | * @var array |
||
| 160 | */ |
||
| 161 | private $entityUpdates = []; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Any pending extra updates that have been scheduled by persisters. |
||
| 165 | * |
||
| 166 | * @var array |
||
| 167 | */ |
||
| 168 | private $extraUpdates = []; |
||
| 169 | |||
| 170 | /** |
||
| 171 | * A list of all pending entity deletions. |
||
| 172 | * |
||
| 173 | * @var array |
||
| 174 | */ |
||
| 175 | private $entityDeletions = []; |
||
| 176 | |||
| 177 | /** |
||
| 178 | * New entities that were discovered through relationships that were not |
||
| 179 | * marked as cascade-persist. During flush, this array is populated and |
||
| 180 | * then pruned of any entities that were discovered through a valid |
||
| 181 | * cascade-persist path. (Leftovers cause an error.) |
||
| 182 | * |
||
| 183 | * Keys are OIDs, payload is a two-item array describing the association |
||
| 184 | * and the entity. |
||
| 185 | * |
||
| 186 | * @var object[][]|array[][] indexed by respective object spl_object_hash() |
||
| 187 | */ |
||
| 188 | private $nonCascadedNewDetectedEntities = []; |
||
| 189 | |||
| 190 | /** |
||
| 191 | * All pending collection deletions. |
||
| 192 | * |
||
| 193 | * @var array |
||
| 194 | */ |
||
| 195 | private $collectionDeletions = []; |
||
| 196 | |||
| 197 | /** |
||
| 198 | * All pending collection updates. |
||
| 199 | * |
||
| 200 | * @var array |
||
| 201 | */ |
||
| 202 | private $collectionUpdates = []; |
||
| 203 | |||
| 204 | /** |
||
| 205 | * List of collections visited during changeset calculation on a commit-phase of a UnitOfWork. |
||
| 206 | * At the end of the UnitOfWork all these collections will make new snapshots |
||
| 207 | * of their data. |
||
| 208 | * |
||
| 209 | * @var array |
||
| 210 | */ |
||
| 211 | private $visitedCollections = []; |
||
| 212 | |||
| 213 | /** |
||
| 214 | * The EntityManager that "owns" this UnitOfWork instance. |
||
| 215 | * |
||
| 216 | * @var EntityManagerInterface |
||
| 217 | */ |
||
| 218 | private $em; |
||
| 219 | |||
| 220 | |||
| 221 | /** |
||
| 222 | * The entity persister instances used to persist entity instances. |
||
| 223 | * |
||
| 224 | * @var array |
||
| 225 | */ |
||
| 226 | private $entityPersisters = []; |
||
| 227 | |||
| 228 | /** |
||
| 229 | * The collection persister instances used to persist collections. |
||
| 230 | * |
||
| 231 | * @var array |
||
| 232 | */ |
||
| 233 | private $collectionPersisters = []; |
||
| 234 | |||
| 235 | /** |
||
| 236 | * The EventManager used for dispatching events. |
||
| 237 | * |
||
| 238 | * @var \Doctrine\Common\EventManager |
||
| 239 | */ |
||
| 240 | private $eventManager; |
||
| 241 | |||
| 242 | /** |
||
| 243 | * The ListenersInvoker used for dispatching events. |
||
| 244 | * |
||
| 245 | * @var \Doctrine\ORM\Event\ListenersInvoker |
||
| 246 | */ |
||
| 247 | private $listenersInvoker; |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @var Instantiator |
||
| 251 | */ |
||
| 252 | private $instantiator; |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Orphaned entities that are scheduled for removal. |
||
| 256 | * |
||
| 257 | * @var array |
||
| 258 | */ |
||
| 259 | private $orphanRemovals = []; |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Read-Only objects are never evaluated |
||
| 263 | * |
||
| 264 | * @var array |
||
| 265 | */ |
||
| 266 | private $readOnlyObjects = []; |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Map of Entity Class-Names and corresponding IDs that should eager loaded when requested. |
||
| 270 | * |
||
| 271 | * @var array |
||
| 272 | */ |
||
| 273 | private $eagerLoadingEntities = []; |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @var boolean |
||
| 277 | */ |
||
| 278 | protected $hasCache = false; |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Helper for handling completion of hydration |
||
| 282 | * |
||
| 283 | * @var HydrationCompleteHandler |
||
| 284 | */ |
||
| 285 | private $hydrationCompleteHandler; |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @var NormalizeIdentifier |
||
| 289 | */ |
||
| 290 | private $normalizeIdentifier; |
||
| 291 | |||
| 292 | 2290 | /** |
|
| 293 | * Initializes a new UnitOfWork instance, bound to the given EntityManager. |
||
| 294 | 2290 | * |
|
| 295 | 2290 | * @param EntityManagerInterface $em |
|
| 296 | 2290 | */ |
|
| 297 | 2290 | public function __construct(EntityManagerInterface $em) |
|
| 298 | 2290 | { |
|
| 299 | 2290 | $this->em = $em; |
|
| 300 | 2290 | $this->eventManager = $em->getEventManager(); |
|
| 301 | 2290 | $this->listenersInvoker = new ListenersInvoker($em); |
|
| 302 | $this->hasCache = $em->getConfiguration()->isSecondLevelCacheEnabled(); |
||
| 303 | $this->instantiator = new Instantiator(); |
||
| 304 | $this->hydrationCompleteHandler = new HydrationCompleteHandler($this->listenersInvoker, $em); |
||
| 305 | $this->normalizeIdentifier = new NormalizeIdentifier(); |
||
| 306 | } |
||
| 307 | |||
| 308 | /** |
||
| 309 | * Commits the UnitOfWork, executing all operations that have been postponed |
||
| 310 | * up to this point. The state of all managed entities will be synchronized with |
||
| 311 | * the database. |
||
| 312 | * |
||
| 313 | * The operations are executed in the following order: |
||
| 314 | * |
||
| 315 | * 1) All entity insertions |
||
| 316 | * 2) All entity updates |
||
| 317 | * 3) All collection deletions |
||
| 318 | * 4) All collection updates |
||
| 319 | * 5) All entity deletions |
||
| 320 | * |
||
| 321 | * @return void |
||
| 322 | 1015 | * |
|
| 323 | * @throws \Exception |
||
| 324 | */ |
||
| 325 | 1015 | public function commit() |
|
| 326 | 2 | { |
|
| 327 | // Raise preFlush |
||
| 328 | if ($this->eventManager->hasListeners(Events::preFlush)) { |
||
| 329 | $this->eventManager->dispatchEvent(Events::preFlush, new PreFlushEventArgs($this->em)); |
||
| 330 | 1015 | } |
|
| 331 | 1007 | ||
| 332 | 16 | $this->computeChangeSets(); |
|
| 333 | 15 | ||
| 334 | 1 | if ( ! ($this->entityInsertions || |
|
|
|
|||
| 335 | 1 | $this->entityDeletions || |
|
| 336 | 1 | $this->entityUpdates || |
|
| 337 | $this->collectionUpdates || |
||
| 338 | $this->collectionDeletions || |
||
| 339 | $this->orphanRemovals)) { |
||
| 340 | 1012 | $this->dispatchOnFlushEvent(); |
|
| 341 | 165 | $this->dispatchPostFlushEvent(); |
|
| 342 | 129 | ||
| 343 | 40 | return; // Nothing to do. |
|
| 344 | 37 | } |
|
| 345 | 1012 | ||
| 346 | 25 | $this->assertThatThereAreNoUnintentionallyNonPersistedAssociations(); |
|
| 347 | 25 | ||
| 348 | if ($this->orphanRemovals) { |
||
| 349 | 25 | foreach ($this->orphanRemovals as $orphan) { |
|
| 350 | $this->remove($orphan); |
||
| 351 | } |
||
| 352 | 1008 | } |
|
| 353 | 16 | ||
| 354 | 16 | $this->dispatchOnFlushEvent(); |
|
| 355 | |||
| 356 | // Now we need a commit order to maintain referential integrity |
||
| 357 | $commitOrder = $this->getCommitOrder(); |
||
| 358 | 1008 | ||
| 359 | $conn = $this->em->getConnection(); |
||
| 360 | $conn->beginTransaction(); |
||
| 361 | 1008 | ||
| 362 | try { |
||
| 363 | 1008 | // Collection deletions (deletions of complete collections) |
|
| 364 | 1008 | foreach ($this->collectionDeletions as $collectionToDelete) { |
|
| 365 | $this->getCollectionPersister($collectionToDelete->getMapping())->delete($collectionToDelete); |
||
| 366 | } |
||
| 367 | |||
| 368 | 1008 | if ($this->entityInsertions) { |
|
| 369 | 19 | foreach ($commitOrder as $class) { |
|
| 370 | $this->executeInserts($class); |
||
| 371 | } |
||
| 372 | 1008 | } |
|
| 373 | 1004 | ||
| 374 | 1004 | if ($this->entityUpdates) { |
|
| 375 | foreach ($commitOrder as $class) { |
||
| 376 | $this->executeUpdates($class); |
||
| 377 | } |
||
| 378 | 1007 | } |
|
| 379 | 115 | ||
| 380 | 115 | // Extra updates that were requested by persisters. |
|
| 381 | if ($this->extraUpdates) { |
||
| 382 | $this->executeExtraUpdates(); |
||
| 383 | } |
||
| 384 | |||
| 385 | 1003 | // Collection updates (deleteRows, updateRows, insertRows) |
|
| 386 | 40 | foreach ($this->collectionUpdates as $collectionToUpdate) { |
|
| 387 | $this->getCollectionPersister($collectionToUpdate->getMapping())->update($collectionToUpdate); |
||
| 388 | } |
||
| 389 | |||
| 390 | 1003 | // Entity deletions come last and need to be in reverse commit order |
|
| 391 | 531 | if ($this->entityDeletions) { |
|
| 392 | foreach (array_reverse($commitOrder) as $committedEntityName) { |
||
| 393 | if (! $this->entityDeletions) { |
||
| 394 | break; // just a performance optimisation |
||
| 395 | 1003 | } |
|
| 396 | 62 | ||
| 397 | 62 | $this->executeDeletions($committedEntityName); |
|
| 398 | } |
||
| 399 | } |
||
| 400 | |||
| 401 | 1003 | $conn->commit(); |
|
| 402 | 11 | } catch (\Throwable $e) { |
|
| 403 | 11 | $this->em->close(); |
|
| 404 | 11 | $conn->rollBack(); |
|
| 405 | |||
| 406 | 11 | $this->afterTransactionRolledBack(); |
|
| 407 | |||
| 408 | 11 | throw $e; |
|
| 409 | } |
||
| 410 | |||
| 411 | 1003 | $this->afterTransactionComplete(); |
|
| 412 | |||
| 413 | // Take new snapshots from visited collections |
||
| 414 | 1003 | foreach ($this->visitedCollections as $coll) { |
|
| 415 | 530 | $coll->takeSnapshot(); |
|
| 416 | } |
||
| 417 | |||
| 418 | 1003 | $this->dispatchPostFlushEvent(); |
|
| 419 | |||
| 420 | // Clean up |
||
| 421 | 1002 | $this->entityInsertions = |
|
| 422 | 1002 | $this->entityUpdates = |
|
| 423 | 1002 | $this->entityDeletions = |
|
| 424 | 1002 | $this->extraUpdates = |
|
| 425 | 1002 | $this->entityChangeSets = |
|
| 426 | 1002 | $this->collectionUpdates = |
|
| 427 | 1002 | $this->collectionDeletions = |
|
| 428 | 1002 | $this->visitedCollections = |
|
| 429 | 1002 | $this->scheduledForSynchronization = |
|
| 430 | 1002 | $this->orphanRemovals = []; |
|
| 431 | 1002 | } |
|
| 432 | |||
| 433 | /** |
||
| 434 | * Computes the changesets of all entities scheduled for insertion. |
||
| 435 | * |
||
| 436 | * @return void |
||
| 437 | */ |
||
| 438 | 1014 | private function computeScheduleInsertsChangeSets() |
|
| 446 | |||
| 447 | /** |
||
| 448 | * Executes any extra updates that have been scheduled. |
||
| 449 | */ |
||
| 450 | private function executeExtraUpdates() |
||
| 465 | 16 | ||
| 466 | 1 | /** |
|
| 467 | * Gets the changeset for an entity. |
||
| 468 | * |
||
| 469 | 15 | * @param object $entity |
|
| 470 | * |
||
| 471 | 15 | * @return array |
|
| 472 | 14 | */ |
|
| 473 | public function & getEntityChangeSet($entity) |
||
| 484 | 2 | ||
| 485 | /** |
||
| 486 | * Computes the changes that happened to a single entity. |
||
| 487 | * |
||
| 488 | 13 | * Modifies/populates the following properties: |
|
| 489 | * |
||
| 490 | 13 | * {@link originalEntityData} |
|
| 491 | 6 | * If the entity is NEW or MANAGED but not yet fully persisted (only has an id) |
|
| 492 | * then it was not fetched from the database and therefore we have no original |
||
| 493 | 12 | * entity data yet. All of the current entity data is stored as the original entity data. |
|
| 494 | * |
||
| 495 | * {@link entityChangeSets} |
||
| 496 | * The changes detected on all properties of the entity are stored there. |
||
| 497 | * A change is a tuple array where the first entry is the old value and the second |
||
| 498 | 40 | * entry is the new value of the property. Changesets are used by persisters |
|
| 499 | * to INSERT/UPDATE the persistent entity state. |
||
| 500 | 40 | * |
|
| 501 | 40 | * {@link entityUpdates} |
|
| 502 | * If the entity is already fully MANAGED (has been fetched from the database before) |
||
| 503 | 40 | * and any changes to its properties are detected, then a reference to the entity is stored |
|
| 504 | * there to mark it for an update. |
||
| 505 | * |
||
| 506 | * {@link collectionDeletions} |
||
| 507 | * If a PersistentCollection has been de-referenced in a fully MANAGED entity, |
||
| 508 | 40 | * then this collection is marked for deletion. |
|
| 509 | * |
||
| 510 | * @ignore |
||
| 511 | 40 | * |
|
| 512 | 40 | * @internal Don't call from the outside. |
|
| 513 | * |
||
| 514 | * @param ClassMetadata $class The class descriptor of the entity. |
||
| 515 | * @param object $entity The entity for which to compute the changes. |
||
| 516 | * |
||
| 517 | * @return void |
||
| 518 | */ |
||
| 519 | public function computeChangeSet(ClassMetadata $class, $entity) |
||
| 728 | |||
| 729 | /** |
||
| 730 | * Computes all the changes that have been done to entities and collections |
||
| 731 | * since the last commit and stores these changes in the _entityChangeSet map |
||
| 732 | 1016 | * temporarily for access by the persisters, until the UoW commit is finished. |
|
| 733 | 894 | * |
|
| 734 | 639 | * @return void |
|
| 735 | */ |
||
| 736 | public function computeChangeSets() |
||
| 776 | 446 | ||
| 777 | 444 | private function computeToManyAssociationChanges(ToManyAssociationMetadata $association, $value) |
|
| 843 | |||
| 844 | /** |
||
| 845 | * Computes the changes of an association. |
||
| 846 | * |
||
| 847 | 716 | * @param AssociationMetadata $association The association mapping. |
|
| 848 | 39 | * @param mixed $value The value of the association. |
|
| 849 | 4 | * |
|
| 850 | * @throws ORMInvalidArgumentException |
||
| 851 | * @throws ORMException |
||
| 852 | 35 | * |
|
| 853 | 35 | * @return void |
|
| 854 | 35 | */ |
|
| 855 | private function computeAssociationChanges(AssociationMetadata $association, $value) |
||
| 924 | |||
| 925 | /** |
||
| 926 | * @param \Doctrine\ORM\Mapping\ClassMetadata $class |
||
| 927 | * @param object $entity |
||
| 928 | * |
||
| 929 | 16 | * @return void |
|
| 930 | */ |
||
| 931 | 16 | private function persistNew($class, $entity) |
|
| 953 | |||
| 954 | /** |
||
| 955 | * INTERNAL: |
||
| 956 | 16 | * Computes the changeset of an individual entity, independently of the |
|
| 957 | * computeChangeSets() routine that is used at the beginning of a UnitOfWork#commit(). |
||
| 958 | * |
||
| 959 | * The passed entity must be a managed entity. If the entity already has a change set |
||
| 960 | 16 | * because this method is invoked during a commit cycle then the change sets are added. |
|
| 961 | 16 | * whereby changes detected in this method prevail. |
|
| 962 | * |
||
| 963 | 16 | * @ignore |
|
| 964 | 16 | * |
|
| 965 | * @param ClassMetadata $class The class descriptor of the entity. |
||
| 966 | 16 | * @param object $entity The entity for which to (re)calculate the change set. |
|
| 967 | 16 | * |
|
| 968 | * @return void |
||
| 969 | * |
||
| 970 | * @throws ORMInvalidArgumentException If the passed entity is not MANAGED. |
||
| 971 | 16 | * @throws \RuntimeException |
|
| 972 | 7 | */ |
|
| 973 | 6 | public function recomputeSingleEntityChangeSet(ClassMetadata $class, $entity) : void |
|
| 1038 | |||
| 1039 | /** |
||
| 1040 | * Executes all entity insertions for entities of the specified type. |
||
| 1041 | * |
||
| 1042 | * @param ClassMetadata $class |
||
| 1043 | 115 | * |
|
| 1044 | * @return void |
||
| 1045 | 115 | */ |
|
| 1046 | 115 | private function executeInserts(ClassMetadata $class) : void |
|
| 1081 | |||
| 1082 | /** |
||
| 1083 | 62 | * Executes all entity updates for entities of the specified type. |
|
| 1084 | * |
||
| 1085 | 62 | * @param \Doctrine\ORM\Mapping\ClassMetadata $class |
|
| 1086 | 62 | * |
|
| 1087 | 62 | * @return void |
|
| 1088 | */ |
||
| 1089 | 62 | private function executeUpdates($class) |
|
| 1121 | |||
| 1122 | /** |
||
| 1123 | 1008 | * Executes all entity deletions for entities of the specified type. |
|
| 1124 | * |
||
| 1125 | 1008 | * @param \Doctrine\ORM\Mapping\ClassMetadata $class |
|
| 1126 | 1008 | * |
|
| 1127 | * @return void |
||
| 1128 | */ |
||
| 1129 | 1008 | private function executeDeletions($class) |
|
| 1167 | 839 | ||
| 1168 | /** |
||
| 1169 | * Gets the commit order. |
||
| 1170 | 839 | * |
|
| 1171 | 832 | * @return array |
|
| 1172 | */ |
||
| 1173 | private function getCommitOrder() |
||
| 1239 | 631 | ||
| 1240 | /** |
||
| 1241 | 631 | * Schedules an entity for insertion into the database. |
|
| 1242 | * If the entity already has an identifier, it will be added to the identity map. |
||
| 1243 | * |
||
| 1244 | * @param object $entity The entity to schedule for insertion. |
||
| 1245 | * |
||
| 1246 | * @return void |
||
| 1247 | * |
||
| 1248 | * @throws ORMInvalidArgumentException |
||
| 1249 | * @throws \InvalidArgumentException |
||
| 1250 | */ |
||
| 1251 | public function scheduleForInsert($entity) |
||
| 1280 | |||
| 1281 | /** |
||
| 1282 | * Checks whether an entity is scheduled for insertion. |
||
| 1283 | * |
||
| 1284 | 40 | * @param object $entity |
|
| 1285 | * |
||
| 1286 | 40 | * @return boolean |
|
| 1287 | 40 | */ |
|
| 1288 | public function isScheduledForInsert($entity) |
||
| 1292 | 1 | ||
| 1293 | /** |
||
| 1294 | * Schedules an entity for being updated. |
||
| 1295 | 40 | * |
|
| 1296 | 40 | * @param object $entity The entity to schedule for being updated. |
|
| 1297 | * |
||
| 1298 | * @return void |
||
| 1299 | * |
||
| 1300 | * @throws ORMInvalidArgumentException |
||
| 1301 | */ |
||
| 1302 | public function scheduleForUpdate($entity) : void |
||
| 1318 | |||
| 1319 | 1 | /** |
|
| 1320 | * INTERNAL: |
||
| 1321 | 1 | * Schedules an extra update that will be executed immediately after the |
|
| 1322 | * regular entity updates within the currently running commit cycle. |
||
| 1323 | 1 | * |
|
| 1324 | * Extra updates for entities are stored as (entity, changeset) tuples. |
||
| 1325 | * |
||
| 1326 | * @ignore |
||
| 1327 | * |
||
| 1328 | * @param object $entity The entity for which to schedule an extra update. |
||
| 1329 | * @param array $changeset The changeset of the entity (what to update). |
||
| 1330 | * |
||
| 1331 | * @return void |
||
| 1332 | */ |
||
| 1333 | public function scheduleExtraUpdate($entity, array $changeset) : void |
||
| 1346 | |||
| 1347 | /** |
||
| 1348 | 65 | * Checks whether an entity is registered as dirty in the unit of work. |
|
| 1349 | 1 | * Note: Is not very useful currently as dirty entities are only registered |
|
| 1350 | * at commit time. |
||
| 1351 | * |
||
| 1352 | 64 | * @param object $entity |
|
| 1353 | * |
||
| 1354 | 64 | * @return boolean |
|
| 1355 | */ |
||
| 1356 | 64 | public function isScheduledForUpdate($entity) : bool |
|
| 1360 | 64 | ||
| 1361 | /** |
||
| 1362 | * Checks whether an entity is registered to be checked in the unit of work. |
||
| 1363 | * |
||
| 1364 | * @param object $entity |
||
| 1365 | * |
||
| 1366 | * @return boolean |
||
| 1367 | */ |
||
| 1368 | public function isScheduledForDirtyCheck($entity) : bool |
||
| 1374 | |||
| 1375 | /** |
||
| 1376 | * INTERNAL: |
||
| 1377 | * Schedules an entity for deletion. |
||
| 1378 | * |
||
| 1379 | * @param object $entity |
||
| 1380 | * |
||
| 1381 | * @return void |
||
| 1382 | */ |
||
| 1383 | public function scheduleForDelete($entity) |
||
| 1410 | |||
| 1411 | 1098 | /** |
|
| 1412 | 6 | * Checks whether an entity is registered as removed/deleted with the unit |
|
| 1413 | * of work. |
||
| 1414 | * |
||
| 1415 | 1092 | * @param object $entity |
|
| 1416 | 1092 | * |
|
| 1417 | * @return boolean |
||
| 1418 | 1092 | */ |
|
| 1419 | 83 | public function isScheduledForDelete($entity) |
|
| 1423 | |||
| 1424 | 1092 | /** |
|
| 1425 | * Checks whether an entity is scheduled for insertion, update or deletion. |
||
| 1426 | * |
||
| 1427 | * @param object $entity |
||
| 1428 | * |
||
| 1429 | * @return boolean |
||
| 1430 | */ |
||
| 1431 | public function isEntityScheduled($entity) |
||
| 1439 | |||
| 1440 | 1045 | /** |
|
| 1441 | * INTERNAL: |
||
| 1442 | 1045 | * Registers an entity in the identity map. |
|
| 1443 | 783 | * Note that entities in a hierarchy are registered with the class name of |
|
| 1444 | * the root entity. |
||
| 1445 | * |
||
| 1446 | 1039 | * @ignore |
|
| 1447 | 1035 | * |
|
| 1448 | * @param object $entity The entity to register. |
||
| 1449 | * |
||
| 1450 | * @return boolean TRUE if the registration was successful, FALSE if the identity of |
||
| 1451 | * the entity in question is already managed. |
||
| 1452 | * |
||
| 1453 | * @throws ORMInvalidArgumentException |
||
| 1454 | 13 | */ |
|
| 1455 | 13 | public function addToIdentityMap($entity) |
|
| 1475 | 4 | ||
| 1476 | 1 | /** |
|
| 1477 | * Gets the state of an entity with regard to the current unit of work. |
||
| 1478 | * |
||
| 1479 | * @param object $entity |
||
| 1480 | 4 | * @param int|null $assume The state to assume if the state is not yet known (not MANAGED or REMOVED). |
|
| 1481 | * This parameter can be set to improve performance of entity state detection |
||
| 1482 | * by potentially avoiding a database lookup if the distinction between NEW and DETACHED |
||
| 1483 | * is either known or does not matter for the caller of the method. |
||
| 1484 | 4 | * |
|
| 1485 | * @return int The entity state. |
||
| 1486 | 5 | */ |
|
| 1487 | public function getEntityState($entity, $assume = null) |
||
| 1559 | |||
| 1560 | /** |
||
| 1561 | * INTERNAL: |
||
| 1562 | * Removes an entity from the identity map. This effectively detaches the |
||
| 1563 | * entity from the persistence management of Doctrine. |
||
| 1564 | * |
||
| 1565 | * @ignore |
||
| 1566 | * |
||
| 1567 | * @param object $entity |
||
| 1568 | * |
||
| 1569 | * @return boolean |
||
| 1570 | * |
||
| 1571 | * @throws ORMInvalidArgumentException |
||
| 1572 | */ |
||
| 1573 | 34 | public function removeFromIdentityMap($entity) |
|
| 1596 | |||
| 1597 | 197 | /** |
|
| 1598 | 197 | * INTERNAL: |
|
| 1599 | * Gets an entity in the identity map by its identifier hash. |
||
| 1600 | 197 | * |
|
| 1601 | * @ignore |
||
| 1602 | * |
||
| 1603 | * @param string $idHash |
||
| 1604 | 197 | * @param string $rootClassName |
|
| 1605 | * |
||
| 1606 | * @return object |
||
| 1607 | */ |
||
| 1608 | public function getByIdHash($idHash, $rootClassName) |
||
| 1612 | |||
| 1613 | /** |
||
| 1614 | * INTERNAL: |
||
| 1615 | * Tries to get an entity by its identifier hash. If no entity is found for |
||
| 1616 | * the given hash, FALSE is returned. |
||
| 1617 | * |
||
| 1618 | * @ignore |
||
| 1619 | * |
||
| 1620 | * @param mixed $idHash (must be possible to cast it to string) |
||
| 1621 | * @param string $rootClassName |
||
| 1622 | * |
||
| 1623 | * @return object|bool The found entity or FALSE. |
||
| 1624 | */ |
||
| 1625 | public function tryGetByIdHash($idHash, $rootClassName) |
||
| 1631 | |||
| 1632 | 1028 | /** |
|
| 1633 | * Checks whether an entity is registered in the identity map of this UnitOfWork. |
||
| 1634 | 1028 | * |
|
| 1635 | 1021 | * @param object $entity |
|
| 1636 | * |
||
| 1637 | * @return boolean |
||
| 1638 | */ |
||
| 1639 | public function isInIdentityMap($entity) |
||
| 1652 | |||
| 1653 | 1028 | /** |
|
| 1654 | * INTERNAL: |
||
| 1655 | 1028 | * Checks whether an identifier hash exists in the identity map. |
|
| 1656 | 109 | * |
|
| 1657 | * @ignore |
||
| 1658 | * |
||
| 1659 | 1028 | * @param string $idHash |
|
| 1660 | * @param string $rootClassName |
||
| 1661 | 1028 | * |
|
| 1662 | * @return boolean |
||
| 1663 | */ |
||
| 1664 | public function containsIdHash($idHash, $rootClassName) |
||
| 1668 | |||
| 1669 | /** |
||
| 1670 | 1028 | * Persists an entity as part of the current unit of work. |
|
| 1671 | * |
||
| 1672 | 234 | * @param object $entity The entity to persist. |
|
| 1673 | 2 | * |
|
| 1674 | * @return void |
||
| 1675 | 234 | */ |
|
| 1676 | public function persist($entity) |
||
| 1682 | |||
| 1683 | 1 | /** |
|
| 1684 | 1 | * Persists an entity as part of the current unit of work. |
|
| 1685 | * |
||
| 1686 | 1 | * This method is internally called during persist() cascades as it tracks |
|
| 1687 | 1 | * the already visited entities to prevent infinite recursions. |
|
| 1688 | * |
||
| 1689 | * @param object $entity The entity to persist. |
||
| 1690 | * @param array $visited The already visited entities. |
||
| 1691 | * |
||
| 1692 | * @return void |
||
| 1693 | * |
||
| 1694 | * @throws ORMInvalidArgumentException |
||
| 1695 | * @throws UnexpectedValueException |
||
| 1696 | */ |
||
| 1697 | 1028 | private function doPersist($entity, array &$visited) |
|
| 1745 | |||
| 1746 | 64 | /** |
|
| 1747 | 64 | * Deletes an entity as part of the current unit of work. |
|
| 1748 | * |
||
| 1749 | 2 | * @param object $entity The entity to remove. |
|
| 1750 | * |
||
| 1751 | 64 | * @return void |
|
| 1752 | 64 | */ |
|
| 1753 | public function remove($entity) |
||
| 1759 | 64 | ||
| 1760 | /** |
||
| 1761 | * Deletes an entity as part of the current unit of work. |
||
| 1762 | * |
||
| 1763 | * This method is internally called during delete() cascades as it tracks |
||
| 1764 | * the already visited entities to prevent infinite recursions. |
||
| 1765 | * |
||
| 1766 | * @param object $entity The entity to delete. |
||
| 1767 | 64 | * @param array $visited The map of the already visited entities. |
|
| 1768 | * |
||
| 1769 | * @return void |
||
| 1770 | * |
||
| 1771 | * @throws ORMInvalidArgumentException If the instance is a detached entity. |
||
| 1772 | * @throws UnexpectedValueException |
||
| 1773 | */ |
||
| 1774 | private function doRemove($entity, array &$visited) |
||
| 1814 | 4 | ||
| 1815 | /** |
||
| 1816 | * Refreshes the state of the given entity from the database, overwriting |
||
| 1817 | 40 | * any local, unpersisted changes. |
|
| 1818 | * |
||
| 1819 | * @param object $entity The entity to refresh. |
||
| 1820 | * |
||
| 1821 | * @return void |
||
| 1822 | * |
||
| 1823 | 40 | * @throws InvalidArgumentException If the entity is not MANAGED. |
|
| 1824 | */ |
||
| 1825 | 40 | public function refresh($entity) |
|
| 1831 | 5 | ||
| 1832 | /** |
||
| 1833 | 5 | * Executes a refresh operation on an entity. |
|
| 1834 | * |
||
| 1835 | 35 | * @param object $entity The entity to refresh. |
|
| 1836 | 3 | * @param array $visited The already visited entities during cascades. |
|
| 1837 | 35 | * |
|
| 1838 | * @return void |
||
| 1839 | 35 | * |
|
| 1840 | * @throws ORMInvalidArgumentException If the entity is not MANAGED. |
||
| 1841 | 35 | */ |
|
| 1842 | private function doRefresh($entity, array &$visited) |
||
| 1865 | |||
| 1866 | /** |
||
| 1867 | * Cascades a refresh operation to associated entities. |
||
| 1868 | 38 | * |
|
| 1869 | 4 | * @param object $entity |
|
| 1870 | 4 | * @param array $visited |
|
| 1871 | * |
||
| 1872 | * @return void |
||
| 1873 | 4 | */ |
|
| 1874 | 1 | private function cascadeRefresh($entity, array &$visited) |
|
| 1907 | |||
| 1908 | /** |
||
| 1909 | * Cascades the save operation to associated entities. |
||
| 1910 | * |
||
| 1911 | * @param object $entity |
||
| 1912 | 38 | * @param array $visited |
|
| 1913 | * |
||
| 1914 | 38 | * @throws ORMInvalidArgumentException |
|
| 1915 | * |
||
| 1916 | * @return void |
||
| 1917 | */ |
||
| 1918 | private function cascadePersist($entity, array &$visited) |
||
| 1975 | 15 | ||
| 1976 | /** |
||
| 1977 | 15 | * Cascades the delete operation to associated entities. |
|
| 1978 | * |
||
| 1979 | * @param object $entity |
||
| 1980 | * @param array $visited |
||
| 1981 | 15 | * |
|
| 1982 | * @return void |
||
| 1983 | 15 | */ |
|
| 1984 | 15 | private function cascadeRemove($entity, array &$visited) |
|
| 2022 | 16 | ||
| 2023 | 16 | /** |
|
| 2024 | * Acquire a lock on the given entity. |
||
| 2025 | * |
||
| 2026 | * @param object $entity |
||
| 2027 | * @param int $lockMode |
||
| 2028 | * @param int $lockVersion |
||
| 2029 | * |
||
| 2030 | * @return void |
||
| 2031 | * |
||
| 2032 | * @throws ORMInvalidArgumentException |
||
| 2033 | * @throws TransactionRequiredException |
||
| 2034 | * @throws OptimisticLockException |
||
| 2035 | 16 | * @throws \InvalidArgumentException |
|
| 2036 | */ |
||
| 2037 | 16 | public function lock($entity, $lockMode, $lockVersion = null) |
|
| 2090 | 5 | ||
| 2091 | /** |
||
| 2092 | * Clears the UnitOfWork. |
||
| 2093 | * |
||
| 2094 | * @return void |
||
| 2095 | */ |
||
| 2096 | 5 | public function clear() |
|
| 2118 | |||
| 2119 | 13 | /** |
|
| 2120 | 3 | * INTERNAL: |
|
| 2121 | * Schedules an orphaned entity for removal. The remove() operation will be |
||
| 2122 | * invoked on that entity at the beginning of the next commit of this |
||
| 2123 | 3 | * UnitOfWork. |
|
| 2124 | * |
||
| 2125 | 2 | * @ignore |
|
| 2126 | * |
||
| 2127 | * @param object $entity |
||
| 2128 | * |
||
| 2129 | * @return void |
||
| 2130 | 3 | */ |
|
| 2131 | 1 | public function scheduleOrphanRemoval($entity) |
|
| 2135 | |||
| 2136 | /** |
||
| 2137 | * INTERNAL: |
||
| 2138 | * Cancels a previously scheduled orphan removal. |
||
| 2139 | 3 | * |
|
| 2140 | * @ignore |
||
| 2141 | * |
||
| 2142 | * @param object $entity |
||
| 2143 | 13 | * |
|
| 2144 | * @return void |
||
| 2145 | */ |
||
| 2146 | public function cancelOrphanRemoval($entity) |
||
| 2150 | |||
| 2151 | /** |
||
| 2152 | * INTERNAL: |
||
| 2153 | * Schedules a complete collection for removal when this UnitOfWork commits. |
||
| 2154 | 38 | * |
|
| 2155 | * @param PersistentCollection $coll |
||
| 2156 | 38 | * |
|
| 2157 | * @return void |
||
| 2158 | 38 | */ |
|
| 2159 | 38 | public function scheduleCollectionDeletion(PersistentCollection $coll) |
|
| 2169 | |||
| 2170 | /** |
||
| 2171 | 8 | * @param PersistentCollection $coll |
|
| 2172 | * |
||
| 2173 | 5 | * @return bool |
|
| 2174 | */ |
||
| 2175 | public function isCollectionScheduledForDeletion(PersistentCollection $coll) |
||
| 2179 | 7 | ||
| 2180 | 14 | /** |
|
| 2181 | * INTERNAL: |
||
| 2182 | * Creates a new instance of the mapped class, without invoking the constructor. |
||
| 2183 | 38 | * This is only meant to be used internally, and should not be consumed by end users. |
|
| 2184 | * |
||
| 2185 | * @ignore |
||
| 2186 | * |
||
| 2187 | * @param ClassMetadata $class |
||
| 2188 | * |
||
| 2189 | * @return EntityManagerAware|object |
||
| 2190 | */ |
||
| 2191 | public function newInstance(ClassMetadata $class) |
||
| 2201 | |||
| 2202 | 1028 | /** |
|
| 2203 | 650 | * INTERNAL: |
|
| 2204 | * Creates an entity. Used for reconstitution of persistent entities. |
||
| 2205 | * |
||
| 2206 | 650 | * Internal note: Highly performance-sensitive method. |
|
| 2207 | * |
||
| 2208 | 21 | * @ignore |
|
| 2209 | * |
||
| 2210 | * @param string $className The name of the entity class. |
||
| 2211 | * @param array $data The data for the entity. |
||
| 2212 | 589 | * @param array $hints Any hints to account for during reconstitution/lookup of the entity. |
|
| 2213 | 554 | * |
|
| 2214 | 3 | * @return object The managed entity instance. |
|
| 2215 | 3 | * |
|
| 2216 | * @todo Rename: getOrCreateEntity |
||
| 2217 | */ |
||
| 2218 | public function createEntity($className, array $data, &$hints = []) |
||
| 2507 | 806 | ||
| 2508 | 310 | /** |
|
| 2509 | 310 | * @return void |
|
| 2510 | */ |
||
| 2511 | public function triggerEagerLoads() |
||
| 2533 | |||
| 2534 | 21 | /** |
|
| 2535 | 21 | * Initializes (loads) an uninitialized persistent collection of an entity. |
|
| 2536 | * |
||
| 2537 | * @param \Doctrine\ORM\PersistentCollection $collection The collection to initialize. |
||
| 2538 | 289 | * |
|
| 2539 | * @return void |
||
| 2540 | * |
||
| 2541 | 289 | * @todo Maybe later move to EntityManager#initialize($proxyOrCollection). See DDC-733. |
|
| 2542 | 71 | */ |
|
| 2543 | public function loadCollection(PersistentCollection $collection) |
||
| 2556 | 665 | ||
| 2557 | /** |
||
| 2558 | 665 | * Gets the identity map of the UnitOfWork. |
|
| 2559 | 665 | * |
|
| 2560 | 665 | * @return array |
|
| 2561 | */ |
||
| 2562 | 665 | public function getIdentityMap() |
|
| 2566 | |||
| 2567 | /** |
||
| 2568 | 665 | * Gets the original data of an entity. The original data is the data that was |
|
| 2569 | * present at the time the entity was reconstituted from the database. |
||
| 2570 | * |
||
| 2571 | 805 | * @param object $entity |
|
| 2572 | 219 | * |
|
| 2573 | * @return array |
||
| 2574 | */ |
||
| 2575 | 702 | public function getOriginalEntityData($entity) |
|
| 2581 | |||
| 2582 | 702 | /** |
|
| 2583 | * @ignore |
||
| 2584 | 702 | * |
|
| 2585 | * @param object $entity |
||
| 2586 | * @param array $data |
||
| 2587 | * |
||
| 2588 | * @return void |
||
| 2589 | 702 | */ |
|
| 2590 | 33 | public function setOriginalEntityData($entity, array $data) |
|
| 2594 | |||
| 2595 | 586 | /** |
|
| 2596 | 260 | * INTERNAL: |
|
| 2597 | * Sets a property value of the original data array of an entity. |
||
| 2598 | * |
||
| 2599 | 564 | * @ignore |
|
| 2600 | * |
||
| 2601 | * @param string $oid |
||
| 2602 | 564 | * @param string $property |
|
| 2603 | 485 | * @param mixed $value |
|
| 2604 | * |
||
| 2605 | * @return void |
||
| 2606 | 64 | */ |
|
| 2607 | public function setOriginalEntityProperty($oid, $property, $value) |
||
| 2611 | 2 | ||
| 2612 | /** |
||
| 2613 | 2 | * Gets the identifier of an entity. |
|
| 2614 | * The returned value is always an array of identifier values. If the entity |
||
| 2615 | * has a composite identifier then the identifier values are in the same |
||
| 2616 | * order as the identifier field names as returned by ClassMetadata#getIdentifierFieldNames(). |
||
| 2617 | 62 | * |
|
| 2618 | * @param object $entity |
||
| 2619 | 62 | * |
|
| 2620 | * @return array The identifier values. |
||
| 2621 | */ |
||
| 2622 | public function getEntityIdentifier($entity) |
||
| 2626 | |||
| 2627 | 38 | /** |
|
| 2628 | * Processes an entity instance to extract their identifier values. |
||
| 2629 | * |
||
| 2630 | 478 | * @param object $entity The entity instance. |
|
| 2631 | * |
||
| 2632 | * @return mixed A scalar value. |
||
| 2633 | 478 | * |
|
| 2634 | 478 | * @throws \Doctrine\ORM\ORMInvalidArgumentException |
|
| 2635 | 478 | */ |
|
| 2636 | public function getSingleIdentifierValue($entity) |
||
| 2651 | |||
| 2652 | 287 | /** |
|
| 2653 | * @param array $id |
||
| 2654 | * @param string $rootClassName |
||
| 2655 | 284 | * |
|
| 2656 | 281 | * @return GhostObjectInterface|object |
|
| 2657 | */ |
||
| 2658 | private function tryGetByIdOrLoadProxy(array $id, string $rootClassName) |
||
| 2684 | |||
| 2685 | /** |
||
| 2686 | * Tries to find an entity with the given identifier in the identity map of |
||
| 2687 | 30 | * this UnitOfWork. |
|
| 2688 | 30 | * |
|
| 2689 | * @param mixed $id The entity identifier to look for. |
||
| 2690 | * @param string $rootClassName The name of the root class of the mapped entity hierarchy. |
||
| 2691 | * |
||
| 2692 | * @return object|bool Returns the entity with the specified identifier if it exists in |
||
| 2693 | 163 | * this UnitOfWork, FALSE otherwise. |
|
| 2694 | 157 | */ |
|
| 2695 | 157 | public function tryGetById($id, $rootClassName) |
|
| 2701 | |||
| 2702 | 6 | /** |
|
| 2703 | 6 | * Schedules an entity for dirty-checking at commit-time. |
|
| 2704 | * |
||
| 2705 | * @param object $entity The entity to schedule for dirty-checking. |
||
| 2706 | * |
||
| 2707 | * @return void |
||
| 2708 | */ |
||
| 2709 | public function scheduleForSynchronization($entity) |
||
| 2715 | |||
| 2716 | /** |
||
| 2717 | 163 | * Checks whether the UnitOfWork has any pending insertions. |
|
| 2718 | 163 | * |
|
| 2719 | * @return boolean TRUE if this UnitOfWork has pending insertions, FALSE otherwise. |
||
| 2720 | */ |
||
| 2721 | public function hasPendingInsertions() |
||
| 2725 | |||
| 2726 | /** |
||
| 2727 | 284 | * Calculates the size of the UnitOfWork. The size of the UnitOfWork is the |
|
| 2728 | 284 | * number of entities in the identity map. |
|
| 2729 | * |
||
| 2730 | 284 | * @return integer |
|
| 2731 | 49 | */ |
|
| 2732 | 49 | public function size() |
|
| 2736 | |||
| 2737 | /** |
||
| 2738 | * Gets the EntityPersister for an Entity. |
||
| 2739 | 486 | * |
|
| 2740 | * @param string $entityName The name of the Entity. |
||
| 2741 | * |
||
| 2742 | * @return \Doctrine\ORM\Persisters\Entity\EntityPersister |
||
| 2743 | */ |
||
| 2744 | 486 | public function getEntityPersister($entityName) |
|
| 2780 | |||
| 2781 | /** |
||
| 2782 | * Gets a collection persister for a collection-valued association. |
||
| 2783 | 861 | * |
|
| 2784 | * @param ToManyAssociationMetadata $association |
||
| 2785 | 861 | * |
|
| 2786 | 861 | * @return \Doctrine\ORM\Persisters\Collection\CollectionPersister |
|
| 2787 | */ |
||
| 2788 | public function getCollectionPersister(ToManyAssociationMetadata $association) |
||
| 2813 | |||
| 2814 | /** |
||
| 2815 | 142 | * INTERNAL: |
|
| 2816 | * Registers an entity as managed. |
||
| 2817 | 142 | * |
|
| 2818 | 142 | * @param object $entity The entity. |
|
| 2819 | * @param array $id Map containing identifier field names as key and its associated values. |
||
| 2820 | 142 | * @param array $data The original entity data. |
|
| 2821 | 142 | * |
|
| 2822 | 76 | * @return void |
|
| 2823 | 76 | */ |
|
| 2824 | public function registerManaged($entity, array $id, array $data) |
||
| 2839 | |||
| 2840 | 2 | /** |
|
| 2841 | * INTERNAL: |
||
| 2842 | * Clears the property changeset of the entity with the given OID. |
||
| 2843 | * |
||
| 2844 | * @param string $oid The entity's OID. |
||
| 2845 | * |
||
| 2846 | * @return void |
||
| 2847 | */ |
||
| 2848 | public function clearEntityChangeSet($oid) |
||
| 2852 | |||
| 2853 | 115 | /* PropertyChangedListener implementation */ |
|
| 2854 | |||
| 2855 | 115 | /** |
|
| 2856 | 112 | * Notifies this UnitOfWork of a property change in an entity. |
|
| 2857 | 115 | * |
|
| 2858 | * @param object $entity The entity that owns the property. |
||
| 2859 | * @param string $propertyName The name of the property that changed. |
||
| 2860 | * @param mixed $oldValue The old value of the property. |
||
| 2861 | * @param mixed $newValue The new value of the property. |
||
| 2862 | * |
||
| 2863 | * @return void |
||
| 2864 | */ |
||
| 2865 | public function propertyChanged($entity, $propertyName, $oldValue, $newValue) |
||
| 2882 | |||
| 2883 | /** |
||
| 2884 | * Gets the currently scheduled entity insertions in this UnitOfWork. |
||
| 2885 | 313 | * |
|
| 2886 | * @return array |
||
| 2887 | 313 | */ |
|
| 2888 | 313 | public function getScheduledEntityInsertions() |
|
| 2892 | |||
| 2893 | /** |
||
| 2894 | * Gets the currently scheduled entity updates in this UnitOfWork. |
||
| 2895 | * |
||
| 2896 | * @return array |
||
| 2897 | */ |
||
| 2898 | public function getScheduledEntityUpdates() |
||
| 2902 | 842 | ||
| 2903 | /** |
||
| 2904 | * Gets the currently scheduled entity deletions in this UnitOfWork. |
||
| 2905 | * |
||
| 2906 | * @return array |
||
| 2907 | */ |
||
| 2908 | public function getScheduledEntityDeletions() |
||
| 2912 | |||
| 2913 | /** |
||
| 2914 | 126 | * Gets the currently scheduled complete collection deletions |
|
| 2915 | * |
||
| 2916 | 126 | * @return array |
|
| 2917 | */ |
||
| 2918 | 126 | public function getScheduledCollectionDeletions() |
|
| 2922 | 126 | ||
| 2923 | 113 | /** |
|
| 2924 | 126 | * Gets the currently scheduled collection inserts, updates and deletes. |
|
| 2925 | * |
||
| 2926 | 126 | * @return array |
|
| 2927 | */ |
||
| 2928 | public function getScheduledCollectionUpdates() |
||
| 2932 | |||
| 2933 | /** |
||
| 2934 | * Helper method to initialize a lazy loading proxy or persistent collection. |
||
| 2935 | * |
||
| 2936 | * @param object $obj |
||
| 2937 | * |
||
| 2938 | * @return void |
||
| 2939 | 522 | */ |
|
| 2940 | public function initializeObject($obj) |
||
| 2952 | |||
| 2953 | /** |
||
| 2954 | * Helper method to show an object as string. |
||
| 2955 | * |
||
| 2956 | * @param object $obj |
||
| 2957 | 5 | * |
|
| 2958 | * @return string |
||
| 2959 | 5 | */ |
|
| 2960 | private static function objToStr($obj) |
||
| 2964 | |||
| 2965 | /** |
||
| 2966 | * Marks an entity as read-only so that it will not be considered for updates during UnitOfWork#commit(). |
||
| 2967 | * |
||
| 2968 | * This operation cannot be undone as some parts of the UnitOfWork now keep gathering information |
||
| 2969 | * on this object that might be necessary to perform a correct update. |
||
| 2970 | * |
||
| 2971 | * @param object $object |
||
| 2972 | * |
||
| 2973 | * @return void |
||
| 2974 | * |
||
| 2975 | * @throws ORMInvalidArgumentException |
||
| 2976 | */ |
||
| 2977 | public function markReadOnly($object) |
||
| 2985 | |||
| 2986 | /** |
||
| 2987 | * Is this entity read only? |
||
| 2988 | * |
||
| 2989 | * @param object $object |
||
| 2990 | * |
||
| 2991 | * @return bool |
||
| 2992 | * |
||
| 2993 | * @throws ORMInvalidArgumentException |
||
| 2994 | 1063 | */ |
|
| 2995 | public function isReadOnly($object) |
||
| 3003 | 1063 | ||
| 3004 | 1031 | /** |
|
| 3005 | 1031 | * Perform whatever processing is encapsulated here after completion of the transaction. |
|
| 3006 | */ |
||
| 3007 | 354 | private function afterTransactionComplete() |
|
| 3013 | 333 | ||
| 3014 | /** |
||
| 3015 | * Perform whatever processing is encapsulated here after completion of the rolled-back. |
||
| 3016 | */ |
||
| 3017 | private function afterTransactionRolledBack() |
||
| 3023 | 119 | ||
| 3024 | /** |
||
| 3025 | * Performs an action after the transaction. |
||
| 3026 | 1063 | * |
|
| 3027 | * @param callable $callback |
||
| 3028 | 1063 | */ |
|
| 3029 | private function performCallbackOnCachedPersister(callable $callback) |
||
| 3041 | 76 | ||
| 3042 | 569 | private function dispatchOnFlushEvent() |
|
| 3048 | 569 | ||
| 3049 | 403 | private function dispatchPostFlushEvent() |
|
| 3055 | 75 | ||
| 3056 | 75 | /** |
|
| 3057 | * Verifies if two given entities actually are the same based on identifier comparison |
||
| 3058 | * |
||
| 3059 | 569 | * @param object $entity1 |
|
| 3060 | * @param object $entity2 |
||
| 3061 | 569 | * |
|
| 3062 | * @return bool |
||
| 3063 | */ |
||
| 3064 | private function isIdentifierEquals($entity1, $entity2) |
||
| 3089 | |||
| 3090 | /** |
||
| 3091 | * @throws ORMInvalidArgumentException |
||
| 3092 | */ |
||
| 3093 | private function assertThatThereAreNoUnintentionallyNonPersistedAssociations() : void |
||
| 3105 | |||
| 3106 | /** |
||
| 3107 | * This method called by hydrators, and indicates that hydrator totally completed current hydration cycle. |
||
| 3108 | * Unit of work able to fire deferred events, related to loading events here. |
||
| 3109 | * |
||
| 3110 | * @internal should be called internally from object hydrators |
||
| 3111 | */ |
||
| 3112 | public function hydrationComplete() |
||
| 3116 | } |
||
| 3117 |
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.