ObjectManager.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 LGPL. 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. 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. public 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. public 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. */
  67. public function merge($object);
  68. /**
  69. * Detaches an object from the ObjectManager, causing a managed object to
  70. * become detached. Unflushed changes made to the object if any
  71. * (including removal of the object), will not be synchronized to the database.
  72. * Objects which previously referenced the detached object will continue to
  73. * reference it.
  74. *
  75. * @param object $object The object to detach.
  76. */
  77. public function detach($object);
  78. /**
  79. * Refreshes the persistent state of an object from the database,
  80. * overriding any local changes that have not yet been persisted.
  81. *
  82. * @param object $object The object to refresh.
  83. */
  84. public function refresh($object);
  85. /**
  86. * Flushes all changes to objects that have been queued up to now to the database.
  87. * This effectively synchronizes the in-memory state of managed objects with the
  88. * database.
  89. */
  90. public function flush();
  91. /**
  92. * Gets the repository for a class.
  93. *
  94. * @param string $className
  95. * @return \Doctrine\Common\Persistence\ObjectRepository
  96. */
  97. public function getRepository($className);
  98. /**
  99. * Returns the ClassMetadata descriptor for a class.
  100. *
  101. * The class name must be the fully-qualified class name without a leading backslash
  102. * (as it is returned by get_class($obj)).
  103. *
  104. * @param string $className
  105. * @return \Doctrine\Common\Persistence\Mapping\ClassMetadata
  106. */
  107. public function getClassMetadata($className);
  108. /**
  109. * Gets the metadata factory used to gather the metadata of classes.
  110. *
  111. * @return Doctrine\Common\Persistence\Mapping\ClassMetadataFactory
  112. */
  113. public function getMetadataFactory();
  114. }