Event.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 bool 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. *
  46. * @return bool Whether propagation was already stopped for this event.
  47. *
  48. * @api
  49. */
  50. public function isPropagationStopped()
  51. {
  52. return $this->propagationStopped;
  53. }
  54. /**
  55. * Stops the propagation of the event to further event listeners.
  56. *
  57. * If multiple event listeners are connected to the same event, no
  58. * further event listener will be triggered once any trigger calls
  59. * stopPropagation().
  60. *
  61. * @api
  62. */
  63. public function stopPropagation()
  64. {
  65. $this->propagationStopped = true;
  66. }
  67. /**
  68. * Stores the EventDispatcher that dispatches this Event.
  69. *
  70. * @param EventDispatcherInterface $dispatcher
  71. *
  72. * @deprecated since version 2.4, to be removed in 3.0. The event dispatcher is passed to the listener call.
  73. *
  74. * @api
  75. */
  76. public function setDispatcher(EventDispatcherInterface $dispatcher)
  77. {
  78. $this->dispatcher = $dispatcher;
  79. }
  80. /**
  81. * Returns the EventDispatcher that dispatches this Event.
  82. *
  83. * @return EventDispatcherInterface
  84. *
  85. * @deprecated since version 2.4, to be removed in 3.0. The event dispatcher is passed to the listener call.
  86. *
  87. * @api
  88. */
  89. public function getDispatcher()
  90. {
  91. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0. The event dispatcher instance can be received in the listener call instead.', E_USER_DEPRECATED);
  92. return $this->dispatcher;
  93. }
  94. /**
  95. * Gets the event's name.
  96. *
  97. * @return string
  98. *
  99. * @deprecated since version 2.4, to be removed in 3.0. The event name is passed to the listener call.
  100. *
  101. * @api
  102. */
  103. public function getName()
  104. {
  105. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0. The event name can be received in the listener call instead.', E_USER_DEPRECATED);
  106. return $this->name;
  107. }
  108. /**
  109. * Sets the event's name property.
  110. *
  111. * @param string $name The event name.
  112. *
  113. * @deprecated since version 2.4, to be removed in 3.0. The event name is passed to the listener call.
  114. *
  115. * @api
  116. */
  117. public function setName($name)
  118. {
  119. $this->name = $name;
  120. }
  121. }