Event.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\Contracts\EventDispatcher;
  11. use Psr\EventDispatcher\StoppableEventInterface;
  12. if (interface_exists(StoppableEventInterface::class)) {
  13. /**
  14. * Event is the base class for classes containing event data.
  15. *
  16. * This class contains no event data. It is used by events that do not pass
  17. * state information to an event handler when an event is raised.
  18. *
  19. * You can call the method stopPropagation() to abort the execution of
  20. * further listeners in your event listener.
  21. *
  22. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  23. * @author Jonathan Wage <jonwage@gmail.com>
  24. * @author Roman Borschel <roman@code-factory.org>
  25. * @author Bernhard Schussek <bschussek@gmail.com>
  26. * @author Nicolas Grekas <p@tchwork.com>
  27. */
  28. class Event implements StoppableEventInterface
  29. {
  30. private $propagationStopped = false;
  31. /**
  32. * Returns whether further event listeners should be triggered.
  33. */
  34. public function isPropagationStopped(): bool
  35. {
  36. return $this->propagationStopped;
  37. }
  38. /**
  39. * Stops the propagation of the event to further event listeners.
  40. *
  41. * If multiple event listeners are connected to the same event, no
  42. * further event listener will be triggered once any trigger calls
  43. * stopPropagation().
  44. */
  45. public function stopPropagation(): void
  46. {
  47. $this->propagationStopped = true;
  48. }
  49. }
  50. } else {
  51. /**
  52. * Event is the base class for classes containing event data.
  53. *
  54. * This class contains no event data. It is used by events that do not pass
  55. * state information to an event handler when an event is raised.
  56. *
  57. * You can call the method stopPropagation() to abort the execution of
  58. * further listeners in your event listener.
  59. *
  60. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  61. * @author Jonathan Wage <jonwage@gmail.com>
  62. * @author Roman Borschel <roman@code-factory.org>
  63. * @author Bernhard Schussek <bschussek@gmail.com>
  64. * @author Nicolas Grekas <p@tchwork.com>
  65. */
  66. class Event
  67. {
  68. private $propagationStopped = false;
  69. /**
  70. * Returns whether further event listeners should be triggered.
  71. */
  72. public function isPropagationStopped(): bool
  73. {
  74. return $this->propagationStopped;
  75. }
  76. /**
  77. * Stops the propagation of the event to further event listeners.
  78. *
  79. * If multiple event listeners are connected to the same event, no
  80. * further event listener will be triggered once any trigger calls
  81. * stopPropagation().
  82. */
  83. public function stopPropagation(): void
  84. {
  85. $this->propagationStopped = true;
  86. }
  87. }
  88. }