1
0

Event.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\EventDispatcher;
  8. use Psr\EventDispatcher\StoppableEventInterface;
  9. /**
  10. * Base event class for the event dispatcher service
  11. *
  12. * Typically this class isn't instantiated directly but sub classed for specific
  13. * event types
  14. *
  15. * This class extended \Symfony\Contracts\EventDispatcher\Event until 21.0, since
  16. * 22.0.0 this class directly implements the PSR StoppableEventInterface and no
  17. * longer relies on Symfony. This transition does not come with any changes in API,
  18. * the class has the same methods and behavior before and after this change.
  19. *
  20. * @since 17.0.0
  21. */
  22. class Event implements StoppableEventInterface {
  23. /**
  24. * @var bool
  25. *
  26. * @since 22.0.0
  27. */
  28. private $propagationStopped = false;
  29. /**
  30. * Compatibility constructor
  31. *
  32. * In Nextcloud 17.0.0 this event class used a now deprecated/removed Symfony base
  33. * class that had a constructor (with default arguments). To lower the risk of
  34. * a breaking change (PHP won't allow parent constructor calls if there is none),
  35. * this empty constructor's only purpose is to hopefully not break existing sub-
  36. * classes of this class.
  37. *
  38. * @since 18.0.0
  39. */
  40. public function __construct() {
  41. }
  42. /**
  43. * Stops the propagation of the event to further event listeners
  44. *
  45. * @return void
  46. *
  47. * @since 22.0.0
  48. */
  49. public function stopPropagation(): void {
  50. $this->propagationStopped = true;
  51. }
  52. /**
  53. * {@inheritDoc}
  54. *
  55. * @since 22.0.0
  56. * @see \Psr\EventDispatcher\StoppableEventInterface
  57. */
  58. public function isPropagationStopped(): bool {
  59. return $this->propagationStopped;
  60. }
  61. }