EventArgs.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\Common;
  4. /**
  5. * EventArgs is the base class for classes containing event data.
  6. *
  7. * This class contains no event data. It is used by events that do not pass state
  8. * information to an event handler when an event is raised. The single empty EventArgs
  9. * instance can be obtained through {@link getEmptyInstance}.
  10. */
  11. class EventArgs
  12. {
  13. /**
  14. * Single instance of EventArgs.
  15. *
  16. * @var EventArgs
  17. */
  18. private static $_emptyEventArgsInstance;
  19. /**
  20. * Gets the single, empty and immutable EventArgs instance.
  21. *
  22. * This instance will be used when events are dispatched without any parameter,
  23. * like this: EventManager::dispatchEvent('eventname');
  24. *
  25. * The benefit from this is that only one empty instance is instantiated and shared
  26. * (otherwise there would be instances for every dispatched in the abovementioned form).
  27. *
  28. * @link https://msdn.microsoft.com/en-us/library/system.eventargs.aspx
  29. * @see EventManager::dispatchEvent
  30. *
  31. * @return EventArgs
  32. */
  33. public static function getEmptyInstance()
  34. {
  35. if (! self::$_emptyEventArgsInstance) {
  36. self::$_emptyEventArgsInstance = new EventArgs();
  37. }
  38. return self::$_emptyEventArgsInstance;
  39. }
  40. }