ORM.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\ORM\EntityManager;
  7. /**
  8. * Doctrine event adapter for ORM specific
  9. * event arguments
  10. *
  11. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  12. * @package Gedmo.Mapping.Event.Adapter
  13. * @subpackage ORM
  14. * @link http://www.gediminasm.org
  15. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  16. */
  17. class ORM implements AdapterInterface
  18. {
  19. /**
  20. * @var \Doctrine\Common\EventArgs
  21. */
  22. private $args;
  23. /**
  24. * @var \Doctrine\ORM\EntityManager
  25. */
  26. private $em;
  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 'Entity';
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function getManagerName()
  45. {
  46. return 'ORM';
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function __call($method, $args)
  52. {
  53. if (is_null($this->args)) {
  54. throw new RuntimeException("Event args must be set before calling its methods");
  55. }
  56. $method = str_replace('Object', $this->getDomainObjectName(), $method);
  57. return call_user_func_array(array($this->args, $method), $args);
  58. }
  59. /**
  60. * Set the entity manager
  61. *
  62. * @param \Doctrine\ORM\EntityManager $em
  63. */
  64. public function setEntityManager(EntityManager $em)
  65. {
  66. $this->em = $em;
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function getObjectManager()
  72. {
  73. if (!is_null($this->em)) {
  74. return $this->em;
  75. }
  76. return $this->__call('getEntityManager', array());
  77. }
  78. /**
  79. * {@inheritdoc}
  80. */
  81. public function getObjectChangeSet($uow, $object)
  82. {
  83. return $uow->getEntityChangeSet($object);
  84. }
  85. /**
  86. * {@inheritdoc}
  87. */
  88. public function getSingleIdentifierFieldName($meta)
  89. {
  90. return $meta->getSingleIdentifierFieldName();
  91. }
  92. /**
  93. * {@inheritdoc}
  94. */
  95. public function recomputeSingleObjectChangeSet($uow, $meta, $object)
  96. {
  97. $uow->recomputeSingleEntityChangeSet($meta, $object);
  98. }
  99. /**
  100. * {@inheritdoc}
  101. */
  102. public function getScheduledObjectUpdates($uow)
  103. {
  104. return $uow->getScheduledEntityUpdates();
  105. }
  106. /**
  107. * {@inheritdoc}
  108. */
  109. public function getScheduledObjectInsertions($uow)
  110. {
  111. return $uow->getScheduledEntityInsertions();
  112. }
  113. /**
  114. * {@inheritdoc}
  115. */
  116. public function getScheduledObjectDeletions($uow)
  117. {
  118. return $uow->getScheduledEntityDeletions();
  119. }
  120. /**
  121. * {@inheritdoc}
  122. */
  123. public function setOriginalObjectProperty($uow, $oid, $property, $value)
  124. {
  125. $uow->setOriginalEntityProperty($oid, $property, $value);
  126. }
  127. /**
  128. * {@inheritdoc}
  129. */
  130. public function clearObjectChangeSet($uow, $oid)
  131. {
  132. $uow->clearEntityChangeSet($oid);
  133. }
  134. }