ObjectManager.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the MIT license. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\Common\Persistence;
  20. /**
  21. * Contract for a Doctrine persistence layer ObjectManager class to implement.
  22. *
  23. * @link www.doctrine-project.org
  24. * @since 2.1
  25. * @author Benjamin Eberlei <kontakt@beberlei.de>
  26. * @author Jonathan Wage <jonwage@gmail.com>
  27. */
  28. interface ObjectManager
  29. {
  30. /**
  31. * Finds a object by its identifier.
  32. *
  33. * This is just a convenient shortcut for getRepository($className)->find($id).
  34. *
  35. * @param string $className The class name of the object to find.
  36. * @param mixed $id The identity of the object to find.
  37. *
  38. * @return object The found object.
  39. */
  40. public function find($className, $id);
  41. /**
  42. * Tells the ObjectManager to make an instance managed and persistent.
  43. *
  44. * The object will be entered into the database as a result of the flush operation.
  45. *
  46. * NOTE: The persist operation always considers objects that are not yet known to
  47. * this ObjectManager as NEW. Do not pass detached objects to the persist operation.
  48. *
  49. * @param object $object The instance to make managed and persistent.
  50. *
  51. * @return void
  52. */
  53. public function persist($object);
  54. /**
  55. * Removes an object instance.
  56. *
  57. * A removed object will be removed from the database as a result of the flush operation.
  58. *
  59. * @param object $object The object instance to remove.
  60. *
  61. * @return void
  62. */
  63. public function remove($object);
  64. /**
  65. * Merges the state of a detached object into the persistence context
  66. * of this ObjectManager and returns the managed copy of the object.
  67. * The object passed to merge will not become associated/managed with this ObjectManager.
  68. *
  69. * @param object $object
  70. *
  71. * @return object
  72. */
  73. public function merge($object);
  74. /**
  75. * Clears the ObjectManager. All objects that are currently managed
  76. * by this ObjectManager become detached.
  77. *
  78. * @param string|null $objectName if given, only objects of this type will get detached.
  79. *
  80. * @return void
  81. */
  82. public function clear($objectName = null);
  83. /**
  84. * Detaches an object from the ObjectManager, causing a managed object to
  85. * become detached. Unflushed changes made to the object if any
  86. * (including removal of the object), will not be synchronized to the database.
  87. * Objects which previously referenced the detached object will continue to
  88. * reference it.
  89. *
  90. * @param object $object The object to detach.
  91. *
  92. * @return void
  93. */
  94. public function detach($object);
  95. /**
  96. * Refreshes the persistent state of an object from the database,
  97. * overriding any local changes that have not yet been persisted.
  98. *
  99. * @param object $object The object to refresh.
  100. *
  101. * @return void
  102. */
  103. public function refresh($object);
  104. /**
  105. * Flushes all changes to objects that have been queued up to now to the database.
  106. * This effectively synchronizes the in-memory state of managed objects with the
  107. * database.
  108. *
  109. * @return void
  110. */
  111. public function flush();
  112. /**
  113. * Gets the repository for a class.
  114. *
  115. * @param string $className
  116. *
  117. * @return \Doctrine\Common\Persistence\ObjectRepository
  118. */
  119. public function getRepository($className);
  120. /**
  121. * Returns the ClassMetadata descriptor for a class.
  122. *
  123. * The class name must be the fully-qualified class name without a leading backslash
  124. * (as it is returned by get_class($obj)).
  125. *
  126. * @param string $className
  127. *
  128. * @return \Doctrine\Common\Persistence\Mapping\ClassMetadata
  129. */
  130. public function getClassMetadata($className);
  131. /**
  132. * Gets the metadata factory used to gather the metadata of classes.
  133. *
  134. * @return \Doctrine\Common\Persistence\Mapping\ClassMetadataFactory
  135. */
  136. public function getMetadataFactory();
  137. /**
  138. * Helper method to initialize a lazy loading proxy or persistent collection.
  139. *
  140. * This method is a no-op for other objects.
  141. *
  142. * @param object $obj
  143. *
  144. * @return void
  145. */
  146. public function initializeObject($obj);
  147. /**
  148. * Checks if the object is part of the current UnitOfWork and therefore managed.
  149. *
  150. * @param object $object
  151. *
  152. * @return bool
  153. */
  154. public function contains($object);
  155. }