Skip to content

Commit 0df93bc

Browse files
committed
Add dispatcher bridge
1 parent eba0ba4 commit 0df93bc

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Command/ExecuteCommand.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
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;
23+
use Task\Event\TaskExecutionEvent;
2224
use Task\Executor\FailedException;
2325
use Task\Handler\TaskHandlerFactoryInterface;
2426
use Task\Storage\TaskExecutionRepositoryInterface;
@@ -80,9 +82,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
8082
$handler = $this->handlerFactory->create($execution->getHandlerClass());
8183

8284
try {
83-
$this->eventDispatcher->dispatch(new TaskEvent($execution->getTask()),Events::TASK_BEFORE);
85+
$this->dispatch(Events::TASK_BEFORE, new TaskEvent($execution->getTask()));
8486
$result = $handler->handle($execution->getWorkload());
85-
$this->eventDispatcher->dispatch(new TaskEvent($execution),Events::TASK_AFTER);
87+
$this->dispatch(Events::TASK_AFTER, new TaskExecutionEvent($execution->getTask(), $execution));
8688
} catch (\Exception $exception) {
8789
if ($exception instanceof FailedException) {
8890
$errorOutput->writeln(FailedException::class);
@@ -107,4 +109,13 @@ public function isHidden()
107109
{
108110
return true;
109111
}
112+
113+
private function dispatch($eventName, $event)
114+
{
115+
if (class_exists(LegacyEventDispatcherProxy::class)) {
116+
return $this->eventDispatcher->dispatch($event, $eventName);
117+
} else {
118+
return $this->eventDispatcher->dispatch($eventName, $event);
119+
}
120+
}
110121
}

0 commit comments

Comments
 (0)