EventDispatcherInterface.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\EventDispatcherInterface as PsrEventDispatcherInterface;
  12. if (interface_exists(PsrEventDispatcherInterface::class)) {
  13. /**
  14. * Allows providing hooks on domain-specific lifecycles by dispatching events.
  15. */
  16. interface EventDispatcherInterface extends PsrEventDispatcherInterface
  17. {
  18. /**
  19. * Dispatches an event to all registered listeners.
  20. *
  21. * For BC with Symfony 4, the $eventName argument is not declared explicitly on the
  22. * signature of the method. Implementations that are not bound by this BC constraint
  23. * MUST declare it explicitly, as allowed by PHP.
  24. *
  25. * @param object $event The event to pass to the event handlers/listeners
  26. * @param string|null $eventName The name of the event to dispatch. If not supplied,
  27. * the class of $event should be used instead.
  28. *
  29. * @return object The passed $event MUST be returned
  30. */
  31. public function dispatch($event/*, string $eventName = null*/);
  32. }
  33. } else {
  34. /**
  35. * Allows providing hooks on domain-specific lifecycles by dispatching events.
  36. */
  37. interface EventDispatcherInterface
  38. {
  39. /**
  40. * Dispatches an event to all registered listeners.
  41. *
  42. * For BC with Symfony 4, the $eventName argument is not declared explicitly on the
  43. * signature of the method. Implementations that are not bound by this BC constraint
  44. * MUST declare it explicitly, as allowed by PHP.
  45. *
  46. * @param object $event The event to pass to the event handlers/listeners
  47. * @param string|null $eventName The name of the event to dispatch. If not supplied,
  48. * the class of $event should be used instead.
  49. *
  50. * @return object The passed $event MUST be returned
  51. */
  52. public function dispatch($event/*, string $eventName = null*/);
  53. }
  54. }