DispatcherWrapper.php 975 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace Codeception\PHPUnit;
  3. use Symfony\Component\EventDispatcher\Event;
  4. use Symfony\Component\EventDispatcher\EventDispatcher;
  5. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
  6. trait DispatcherWrapper
  7. {
  8. /**
  9. * Compatibility wrapper for dispatcher change between Symfony 4 and 5
  10. * @param EventDispatcher $dispatcher
  11. * @param string $eventType
  12. * @param Event $eventObject
  13. */
  14. protected function dispatch(EventDispatcher $dispatcher, $eventType, Event $eventObject)
  15. {
  16. // The `EventDispatcherInterface` of `Symfony\Contracts` is only implemented in Symfony 4.3 or higher
  17. if ($dispatcher instanceof ContractsEventDispatcherInterface) {
  18. //Symfony 4.3 or higher
  19. $dispatcher->dispatch($eventObject, $eventType);
  20. } else {
  21. //Symfony 4.2 or lower
  22. $dispatcher->dispatch($eventType, $eventObject);
  23. }
  24. }
  25. }