PersistenceEvent.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Event;
  11. use Sonata\AdminBundle\Admin\AdminInterface;
  12. use Symfony\Component\EventDispatcher\Event;
  13. /**
  14. * This event is sent by hook:
  15. * - preUpdate | postUpdate
  16. * - prePersist | postPersist
  17. * - preRemove | postRemove.
  18. *
  19. * You can register the listener to the event dispatcher by using:
  20. * - sonata.admin.event.persistence.[pre|post]_[persist|update|remove)
  21. * - sonata.admin.event.persistence.[admin_code].[pre|post]_[persist|update|remove) (not implemented yet)
  22. *
  23. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  24. */
  25. class PersistenceEvent extends Event
  26. {
  27. const TYPE_PRE_UPDATE = 'pre_update';
  28. const TYPE_POST_UPDATE = 'post_update';
  29. const TYPE_PRE_PERSIST = 'pre_persist';
  30. const TYPE_POST_PERSIST = 'post_persist';
  31. const TYPE_PRE_REMOVE = 'pre_remove';
  32. const TYPE_POST_REMOVE = 'post_remove';
  33. /**
  34. * @var AdminInterface
  35. */
  36. protected $admin;
  37. /**
  38. * @var object
  39. */
  40. protected $object;
  41. /**
  42. * @var string
  43. */
  44. protected $type;
  45. /**
  46. * @param AdminInterface $admin
  47. * @param object $object
  48. * @param string $type
  49. */
  50. public function __construct(AdminInterface $admin, $object, $type)
  51. {
  52. $this->admin = $admin;
  53. $this->object = $object;
  54. $this->type = $type;
  55. }
  56. /**
  57. * @return AdminInterface
  58. */
  59. public function getAdmin()
  60. {
  61. return $this->admin;
  62. }
  63. /**
  64. * @return object
  65. */
  66. public function getObject()
  67. {
  68. return $this->object;
  69. }
  70. /**
  71. * @return mixed
  72. */
  73. public function getType()
  74. {
  75. return $this->type;
  76. }
  77. }