EventArgs.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. * @see EventManager::dispatchEvent
  29. *
  30. * @link https://msdn.microsoft.com/en-us/library/system.eventargs.aspx
  31. *
  32. * @return EventArgs
  33. */
  34. public static function getEmptyInstance()
  35. {
  36. if (! self::$_emptyEventArgsInstance) {
  37. self::$_emptyEventArgsInstance = new EventArgs();
  38. }
  39. return self::$_emptyEventArgsInstance;
  40. }
  41. }