ObjectManager.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace Doctrine\Common\Persistence;
  3. use Doctrine\Common\Persistence\Mapping\ClassMetadata;
  4. use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
  5. /**
  6. * Contract for a Doctrine persistence layer ObjectManager class to implement.
  7. */
  8. interface ObjectManager
  9. {
  10. /**
  11. * Finds an object by its identifier.
  12. *
  13. * This is just a convenient shortcut for getRepository($className)->find($id).
  14. *
  15. * @param string $className The class name of the object to find.
  16. * @param mixed $id The identity of the object to find.
  17. *
  18. * @return object|null The found object.
  19. */
  20. public function find($className, $id);
  21. /**
  22. * Tells the ObjectManager to make an instance managed and persistent.
  23. *
  24. * The object will be entered into the database as a result of the flush operation.
  25. *
  26. * NOTE: The persist operation always considers objects that are not yet known to
  27. * this ObjectManager as NEW. Do not pass detached objects to the persist operation.
  28. *
  29. * @param object $object The instance to make managed and persistent.
  30. *
  31. * @return void
  32. */
  33. public function persist($object);
  34. /**
  35. * Removes an object instance.
  36. *
  37. * A removed object will be removed from the database as a result of the flush operation.
  38. *
  39. * @param object $object The object instance to remove.
  40. *
  41. * @return void
  42. */
  43. public function remove($object);
  44. /**
  45. * Merges the state of a detached object into the persistence context
  46. * of this ObjectManager and returns the managed copy of the object.
  47. * The object passed to merge will not become associated/managed with this ObjectManager.
  48. *
  49. * @param object $object
  50. *
  51. * @return object
  52. */
  53. public function merge($object);
  54. /**
  55. * Clears the ObjectManager. All objects that are currently managed
  56. * by this ObjectManager become detached.
  57. *
  58. * @param string|null $objectName if given, only objects of this type will get detached.
  59. *
  60. * @return void
  61. */
  62. public function clear($objectName = null);
  63. /**
  64. * Detaches an object from the ObjectManager, causing a managed object to
  65. * become detached. Unflushed changes made to the object if any
  66. * (including removal of the object), will not be synchronized to the database.
  67. * Objects which previously referenced the detached object will continue to
  68. * reference it.
  69. *
  70. * @param object $object The object to detach.
  71. *
  72. * @return void
  73. */
  74. public function detach($object);
  75. /**
  76. * Refreshes the persistent state of an object from the database,
  77. * overriding any local changes that have not yet been persisted.
  78. *
  79. * @param object $object The object to refresh.
  80. *
  81. * @return void
  82. */
  83. public function refresh($object);
  84. /**
  85. * Flushes all changes to objects that have been queued up to now to the database.
  86. * This effectively synchronizes the in-memory state of managed objects with the
  87. * database.
  88. *
  89. * @return void
  90. */
  91. public function flush();
  92. /**
  93. * Gets the repository for a class.
  94. *
  95. * @param string $className
  96. *
  97. * @return ObjectRepository
  98. */
  99. public function getRepository($className);
  100. /**
  101. * Returns the ClassMetadata descriptor for a class.
  102. *
  103. * The class name must be the fully-qualified class name without a leading backslash
  104. * (as it is returned by get_class($obj)).
  105. *
  106. * @param string $className
  107. *
  108. * @return ClassMetadata
  109. */
  110. public function getClassMetadata($className);
  111. /**
  112. * Gets the metadata factory used to gather the metadata of classes.
  113. *
  114. * @return ClassMetadataFactory
  115. */
  116. public function getMetadataFactory();
  117. /**
  118. * Helper method to initialize a lazy loading proxy or persistent collection.
  119. *
  120. * This method is a no-op for other objects.
  121. *
  122. * @param object $obj
  123. *
  124. * @return void
  125. */
  126. public function initializeObject($obj);
  127. /**
  128. * Checks if the object is part of the current UnitOfWork and therefore managed.
  129. *
  130. * @param object $object
  131. *
  132. * @return bool
  133. */
  134. public function contains($object);
  135. }