PersistenceEvent.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. class PersistenceEvent extends Event
  24. {
  25. const TYPE_PRE_UPDATE = 'pre_update';
  26. const TYPE_POST_UPDATE = 'post_update';
  27. const TYPE_PRE_PERSIST = 'pre_persist';
  28. const TYPE_POST_PERSIST = 'post_persist';
  29. const TYPE_PRE_REMOVE = 'pre_remove';
  30. const TYPE_POST_REMOVE = 'post_remove';
  31. protected $admin;
  32. protected $object;
  33. protected $type;
  34. /**
  35. * @param AdminInterface $admin
  36. * @param object $object
  37. * @param string $type
  38. */
  39. public function __construct(AdminInterface $admin, $object, $type)
  40. {
  41. $this->admin = $admin;
  42. $this->object = $object;
  43. $this->type = $type;
  44. }
  45. /**
  46. * @return \Sonata\AdminBundle\Admin\AdminInterface
  47. */
  48. public function getAdmin()
  49. {
  50. return $this->admin;
  51. }
  52. /**
  53. * @return object
  54. */
  55. public function getObject()
  56. {
  57. return $this->object;
  58. }
  59. /**
  60. * @return mixed
  61. */
  62. public function getType()
  63. {
  64. return $this->type;
  65. }
  66. }