Event.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  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 Symfony\Component\EventDispatcher;
  11. /**
  12. * Event is the base class for classes containing event data.
  13. *
  14. * This class contains no event data. It is used by events that do not pass
  15. * state information to an event handler when an event is raised.
  16. *
  17. * You can call the method stopPropagation() to abort the execution of
  18. * further listeners in your event listener.
  19. *
  20. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  21. * @author Jonathan Wage <jonwage@gmail.com>
  22. * @author Roman Borschel <roman@code-factory.org>
  23. * @author Bernhard Schussek <bschussek@gmail.com>
  24. *
  25. * @api
  26. */
  27. class Event
  28. {
  29. /**
  30. * @var Boolean Whether no further event listeners should be triggered
  31. */
  32. private $propagationStopped = false;
  33. /**
  34. * @var EventDispatcher Dispatcher that dispatched this event
  35. */
  36. private $dispatcher;
  37. /**
  38. * @var string This event's name
  39. */
  40. private $name;
  41. /**
  42. * Returns whether further event listeners should be triggered.
  43. *
  44. * @see Event::stopPropagation
  45. * @return Boolean Whether propagation was already stopped for this event.
  46. *
  47. * @api
  48. */
  49. public function isPropagationStopped()
  50. {
  51. return $this->propagationStopped;
  52. }
  53. /**
  54. * Stops the propagation of the event to further event listeners.
  55. *
  56. * If multiple event listeners are connected to the same event, no
  57. * further event listener will be triggered once any trigger calls
  58. * stopPropagation().
  59. *
  60. * @api
  61. */
  62. public function stopPropagation()
  63. {
  64. $this->propagationStopped = true;
  65. }
  66. /**
  67. * Stores the EventDispatcher that dispatches this Event
  68. *
  69. * @param EventDispatcherInterface $dispatcher
  70. *
  71. * @api
  72. */
  73. public function setDispatcher(EventDispatcherInterface $dispatcher)
  74. {
  75. $this->dispatcher = $dispatcher;
  76. }
  77. /**
  78. * Returns the EventDispatcher that dispatches this Event
  79. *
  80. * @return EventDispatcherInterface
  81. *
  82. * @api
  83. */
  84. public function getDispatcher()
  85. {
  86. return $this->dispatcher;
  87. }
  88. /**
  89. * Gets the event's name.
  90. *
  91. * @return string
  92. *
  93. * @api
  94. */
  95. public function getName()
  96. {
  97. return $this->name;
  98. }
  99. /**
  100. * Sets the event's name property.
  101. *
  102. * @param string $name The event name.
  103. *
  104. * @api
  105. */
  106. public function setName($name)
  107. {
  108. $this->name = $name;
  109. }
  110. }