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,9 @@ 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
+ $ this ->dispatch (Events:: TASK_AFTER , new TaskEvent ($ execution-> getTask ()) );
86
87
} catch (\Exception $ exception ) {
87
88
if ($ exception instanceof FailedException) {
88
89
$ errorOutput ->writeln (FailedException::class);
@@ -107,4 +108,13 @@ public function isHidden()
107
108
{
108
109
return true ;
109
110
}
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
+ }
110
120
}
0 commit comments