ODM.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace Gedmo\Mapping\Event\Adapter;
  3. use Gedmo\Mapping\Event\AdapterInterface;
  4. use Gedmo\Exception\RuntimeException;
  5. use Doctrine\Common\EventArgs;
  6. use Doctrine\ODM\MongoDB\DocumentManager;
  7. /**
  8. * Doctrine event adapter for ODM specific
  9. * event arguments
  10. *
  11. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  12. * @package Gedmo.Mapping.Event.Adapter
  13. * @subpackage ODM
  14. * @link http://www.gediminasm.org
  15. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  16. */
  17. class ODM implements AdapterInterface
  18. {
  19. /**
  20. * @var \Doctrine\Common\EventArgs
  21. */
  22. private $args;
  23. /**
  24. * @var \Doctrine\ODM\MongoDB\DocumentManager
  25. */
  26. private $dm;
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function setEventArgs(EventArgs $args)
  31. {
  32. $this->args = $args;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function getDomainObjectName()
  38. {
  39. return 'Document';
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function getManagerName()
  45. {
  46. return 'ODM';
  47. }
  48. /**
  49. * Set the document manager
  50. *
  51. * @param \Doctrine\ODM\MongoDB\DocumentManager $dm
  52. */
  53. public function setDocumentManager(DocumentManager $dm)
  54. {
  55. $this->dm = $dm;
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. public function getObjectManager()
  61. {
  62. if (!is_null($this->dm)) {
  63. return $this->dm;
  64. }
  65. return $this->__call('getDocumentManager', array());
  66. }
  67. /**
  68. * {@inheritdoc}
  69. */
  70. public function __call($method, $args)
  71. {
  72. if (is_null($this->args)) {
  73. throw new RuntimeException("Event args must be set before calling its methods");
  74. }
  75. $method = str_replace('Object', $this->getDomainObjectName(), $method);
  76. return call_user_func_array(array($this->args, $method), $args);
  77. }
  78. /**
  79. * {@inheritdoc}
  80. */
  81. public function getObjectChangeSet($uow, $object)
  82. {
  83. return $uow->getDocumentChangeSet($object);
  84. }
  85. /**
  86. * {@inheritdoc}
  87. */
  88. public function getSingleIdentifierFieldName($meta)
  89. {
  90. return $meta->identifier;
  91. }
  92. /**
  93. * {@inheritdoc}
  94. */
  95. public function recomputeSingleObjectChangeSet($uow, $meta, $object)
  96. {
  97. $uow->recomputeSingleDocumentChangeSet($meta, $object);
  98. }
  99. /**
  100. * {@inheritdoc}
  101. */
  102. public function getScheduledObjectUpdates($uow)
  103. {
  104. return $uow->getScheduledDocumentUpdates();
  105. }
  106. /**
  107. * {@inheritdoc}
  108. */
  109. public function getScheduledObjectInsertions($uow)
  110. {
  111. return $uow->getScheduledDocumentInsertions();
  112. }
  113. /**
  114. * {@inheritdoc}
  115. */
  116. public function getScheduledObjectDeletions($uow)
  117. {
  118. return $uow->getScheduledDocumentDeletions();
  119. }
  120. /**
  121. * {@inheritdoc}
  122. */
  123. public function setOriginalObjectProperty($uow, $oid, $property, $value)
  124. {
  125. $uow->setOriginalDocumentProperty($oid, $property, $value);
  126. }
  127. /**
  128. * {@inheritdoc}
  129. */
  130. public function clearObjectChangeSet($uow, $oid)
  131. {
  132. $uow->clearDocumentChangeSet($oid);
  133. }
  134. }