ObjectManager.php 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  24. * @link www.doctrine-project.org
  25. * @since 2.1
  26. * @author Benjamin Eberlei <kontakt@beberlei.de>
  27. * @author Jonathan Wage <jonwage@gmail.com>
  28. */
  29. interface ObjectManager
  30. {
  31. /**
  32. * Finds a object by its identifier.
  33. *
  34. * This is just a convenient shortcut for getRepository($className)->find($id).
  35. *
  36. * @param string
  37. * @param mixed
  38. * @return object
  39. */
  40. 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. function persist($object);
  52. /**
  53. * Removes an object instance.
  54. *
  55. * A removed object will be removed from the database as a result of the flush operation.
  56. *
  57. * @param object $object The object instance to remove.
  58. */
  59. function remove($object);
  60. /**
  61. * Merges the state of a detached object into the persistence context
  62. * of this ObjectManager and returns the managed copy of the object.
  63. * The object passed to merge will not become associated/managed with this ObjectManager.
  64. *
  65. * @param object $object
  66. * @return object
  67. */
  68. function merge($object);
  69. /**
  70. * Clears the ObjectManager. All objects that are currently managed
  71. * by this ObjectManager become detached.
  72. *
  73. * @param string $objectName if given, only objects of this type will get detached
  74. */
  75. function clear($objectName = null);
  76. /**
  77. * Detaches an object from the ObjectManager, causing a managed object to
  78. * become detached. Unflushed changes made to the object if any
  79. * (including removal of the object), will not be synchronized to the database.
  80. * Objects which previously referenced the detached object will continue to
  81. * reference it.
  82. *
  83. * @param object $object The object to detach.
  84. */
  85. function detach($object);
  86. /**
  87. * Refreshes the persistent state of an object from the database,
  88. * overriding any local changes that have not yet been persisted.
  89. *
  90. * @param object $object The object to refresh.
  91. */
  92. function refresh($object);
  93. /**
  94. * Flushes all changes to objects that have been queued up to now to the database.
  95. * This effectively synchronizes the in-memory state of managed objects with the
  96. * database.
  97. */
  98. function flush();
  99. /**
  100. * Gets the repository for a class.
  101. *
  102. * @param string $className
  103. * @return \Doctrine\Common\Persistence\ObjectRepository
  104. */
  105. function getRepository($className);
  106. /**
  107. * Returns the ClassMetadata descriptor for a class.
  108. *
  109. * The class name must be the fully-qualified class name without a leading backslash
  110. * (as it is returned by get_class($obj)).
  111. *
  112. * @param string $className
  113. * @return \Doctrine\Common\Persistence\Mapping\ClassMetadata
  114. */
  115. function getClassMetadata($className);
  116. /**
  117. * Gets the metadata factory used to gather the metadata of classes.
  118. *
  119. * @return \Doctrine\Common\Persistence\Mapping\ClassMetadataFactory
  120. */
  121. function getMetadataFactory();
  122. /**
  123. * Helper method to initialize a lazy loading proxy or persistent collection.
  124. *
  125. * This method is a no-op for other objects.
  126. *
  127. * @param object $obj
  128. */
  129. function initializeObject($obj);
  130. /**
  131. * Check if the object is part of the current UnitOfWork and therefore
  132. * managed.
  133. *
  134. * @param object $object
  135. * @return bool
  136. */
  137. function contains($object);
  138. }