Event.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. }