Event.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. class Event
  26. {
  27. /**
  28. * @var bool Whether no further event listeners should be triggered
  29. */
  30. private $propagationStopped = false;
  31. /**
  32. * @var EventDispatcherInterface Dispatcher that dispatched this event
  33. */
  34. private $dispatcher;
  35. /**
  36. * @var string This event's name
  37. */
  38. private $name;
  39. /**
  40. * Returns whether further event listeners should be triggered.
  41. *
  42. * @see Event::stopPropagation()
  43. *
  44. * @return bool Whether propagation was already stopped for this event
  45. */
  46. public function isPropagationStopped()
  47. {
  48. return $this->propagationStopped;
  49. }
  50. /**
  51. * Stops the propagation of the event to further event listeners.
  52. *
  53. * If multiple event listeners are connected to the same event, no
  54. * further event listener will be triggered once any trigger calls
  55. * stopPropagation().
  56. */
  57. public function stopPropagation()
  58. {
  59. $this->propagationStopped = true;
  60. }
  61. /**
  62. * Stores the EventDispatcher that dispatches this Event.
  63. *
  64. * @param EventDispatcherInterface $dispatcher
  65. *
  66. * @deprecated since version 2.4, to be removed in 3.0. The event dispatcher is passed to the listener call.
  67. */
  68. public function setDispatcher(EventDispatcherInterface $dispatcher)
  69. {
  70. $this->dispatcher = $dispatcher;
  71. }
  72. /**
  73. * Returns the EventDispatcher that dispatches this Event.
  74. *
  75. * @return EventDispatcherInterface
  76. *
  77. * @deprecated since version 2.4, to be removed in 3.0. The event dispatcher is passed to the listener call.
  78. */
  79. public function getDispatcher()
  80. {
  81. @trigger_error('The '.__METHOD__.' method is deprecated since Symfony 2.4 and will be removed in 3.0. The event dispatcher instance can be received in the listener call instead.', E_USER_DEPRECATED);
  82. return $this->dispatcher;
  83. }
  84. /**
  85. * Gets the event's name.
  86. *
  87. * @return string
  88. *
  89. * @deprecated since version 2.4, to be removed in 3.0. The event name is passed to the listener call.
  90. */
  91. public function getName()
  92. {
  93. @trigger_error('The '.__METHOD__.' method is deprecated since Symfony 2.4 and will be removed in 3.0. The event name can be received in the listener call instead.', E_USER_DEPRECATED);
  94. return $this->name;
  95. }
  96. /**
  97. * Sets the event's name property.
  98. *
  99. * @param string $name The event name
  100. *
  101. * @deprecated since version 2.4, to be removed in 3.0. The event name is passed to the listener call.
  102. */
  103. public function setName($name)
  104. {
  105. $this->name = $name;
  106. }
  107. }