Skip to content

Commit b496900

Browse files
committed
Add dispatcher bridge
1 parent eba0ba4 commit b496900

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Command/ExecuteCommand.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1818
use Symfony\Component\Console\Output\OutputInterface;
1919
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
20+
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
2021
use Task\Event\Events;
2122
use Task\Event\TaskEvent;
2223
use Task\Executor\FailedException;
@@ -80,9 +81,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
8081
$handler = $this->handlerFactory->create($execution->getHandlerClass());
8182

8283
try {
83-
$this->eventDispatcher->dispatch(new TaskEvent($execution->getTask()),Events::TASK_BEFORE);
84+
$this->dispatch(Events::TASK_BEFORE, new TaskEvent($execution->getTask()));
8485
$result = $handler->handle($execution->getWorkload());
85-
$this->eventDispatcher->dispatch(new TaskEvent($execution),Events::TASK_AFTER);
8686
} catch (\Exception $exception) {
8787
if ($exception instanceof FailedException) {
8888
$errorOutput->writeln(FailedException::class);
@@ -107,4 +107,13 @@ public function isHidden()
107107
{
108108
return true;
109109
}
110+
111+
private function dispatch($eventName, $event)
112+
{
113+
if (class_exists(LegacyEventDispatcherProxy::class)) {
114+
return $this->eventDispatcher->dispatch($event, $eventName);
115+
} else {
116+
return $this->eventDispatcher->dispatch($eventName, $event);
117+
}
118+
}
110119
}

0 commit comments

Comments
 (0)