17
17
use Symfony \Component \Console \Output \ConsoleOutputInterface ;
18
18
use Symfony \Component \Console \Output \OutputInterface ;
19
19
use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
20
+ use Symfony \Component \EventDispatcher \LegacyEventDispatcherProxy ;
20
21
use Task \Event \Events ;
21
22
use Task \Event \TaskEvent ;
22
23
use Task \Executor \FailedException ;
@@ -80,9 +81,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
80
81
$ handler = $ this ->handlerFactory ->create ($ execution ->getHandlerClass ());
81
82
82
83
try {
83
- $ this ->eventDispatcher -> dispatch (new TaskEvent ($ execution ->getTask ()),Events:: TASK_BEFORE );
84
+ $ this ->dispatch (Events:: TASK_BEFORE , new TaskEvent ($ execution ->getTask ()));
84
85
$ result = $ handler ->handle ($ execution ->getWorkload ());
85
- $ this ->eventDispatcher ->dispatch (new TaskEvent ($ execution ),Events::TASK_AFTER );
86
86
} catch (\Exception $ exception ) {
87
87
if ($ exception instanceof FailedException) {
88
88
$ errorOutput ->writeln (FailedException::class);
@@ -107,4 +107,13 @@ public function isHidden()
107
107
{
108
108
return true ;
109
109
}
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
+ }
110
119
}
0 commit comments