PersistenceEvent.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. protected $admin;
  34. protected $object;
  35. protected $type;
  36. /**
  37. * @param AdminInterface $admin
  38. * @param object $object
  39. * @param string $type
  40. */
  41. public function __construct(AdminInterface $admin, $object, $type)
  42. {
  43. $this->admin = $admin;
  44. $this->object = $object;
  45. $this->type = $type;
  46. }
  47. /**
  48. * @return \Sonata\AdminBundle\Admin\AdminInterface
  49. */
  50. public function getAdmin()
  51. {
  52. return $this->admin;
  53. }
  54. /**
  55. * @return object
  56. */
  57. public function getObject()
  58. {
  59. return $this->object;
  60. }
  61. /**
  62. * @return mixed
  63. */
  64. public function getType()
  65. {
  66. return $this->type;
  67. }
  68. }