Skip to content

Commit eed916e

Browse files
committed
Add dispatcher bridge
1 parent eba0ba4 commit eed916e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Command/ExecuteCommand.php

Lines changed: 12 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,9 @@ 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);
86+
$this->dispatch(Events::TASK_AFTER, new TaskEvent($execution->getTask()));
8687
} catch (\Exception $exception) {
8788
if ($exception instanceof FailedException) {
8889
$errorOutput->writeln(FailedException::class);
@@ -107,4 +108,13 @@ public function isHidden()
107108
{
108109
return true;
109110
}
111+
112+
private function dispatch($eventName, $event)
113+
{
114+
if (class_exists(LegacyEventDispatcherProxy::class)) {
115+
return $this->eventDispatcher->dispatch($event, $eventName);
116+
} else {
117+
return $this->eventDispatcher->dispatch($eventName, $event);
118+
}
119+
}
110120
}

0 commit comments

Comments
 (0)