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 ;
23
+ use Task \Event \TaskExecutionEvent ;
22
24
use Task \Executor \FailedException ;
23
25
use Task \Handler \TaskHandlerFactoryInterface ;
24
26
use Task \Storage \TaskExecutionRepositoryInterface ;
@@ -80,9 +82,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
80
82
$ handler = $ this ->handlerFactory ->create ($ execution ->getHandlerClass ());
81
83
82
84
try {
83
- $ this ->eventDispatcher -> dispatch (new TaskEvent ($ execution ->getTask ()),Events:: TASK_BEFORE );
85
+ $ this ->dispatch (Events:: TASK_BEFORE , new TaskEvent ($ execution ->getTask ()));
84
86
$ 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 ) );
86
88
} catch (\Exception $ exception ) {
87
89
if ($ exception instanceof FailedException) {
88
90
$ errorOutput ->writeln (FailedException::class);
@@ -107,4 +109,13 @@ public function isHidden()
107
109
{
108
110
return true ;
109
111
}
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
+ }
110
121
}
0 commit comments