2828use Symfony \Component \Console \Output \OutputInterface ;
2929use Symfony \Component \DependencyInjection \ContainerAwareInterface ;
3030use Symfony \Component \EventDispatcher \EventDispatcher ;
31+ use Symfony \Component \EventDispatcher \LegacyEventDispatcherProxy ;
3132
3233/**
3334 * Main application for PHPCRSH.
@@ -56,6 +57,11 @@ class ShellApplication extends Application
5657 */
5758 protected $ initialized = false ;
5859
60+ /**
61+ * @var EventDispatcher
62+ */
63+ private $ dispatcher ;
64+
5965 /**
6066 * Constructor - name and version inherited from SessionApplication.
6167 *
@@ -94,7 +100,7 @@ public function init()
94100 $ this ->registerShellCommands ();
95101
96102 $ event = new ApplicationInitEvent ($ this );
97- $ this ->dispatcher -> dispatch (PhpcrShellEvents::APPLICATION_INIT , $ event );
103+ $ this ->dispatch (PhpcrShellEvents::APPLICATION_INIT , $ event );
98104 $ this ->initialized = true ;
99105 }
100106
@@ -241,7 +247,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
241247 $ name = $ this ->getCommandName ($ input );
242248
243249 $ event = new Event \CommandPreRunEvent ($ name , $ input );
244- $ this ->dispatcher -> dispatch (PhpcrShellEvents::COMMAND_PRE_RUN , $ event );
250+ $ this ->dispatch (PhpcrShellEvents::COMMAND_PRE_RUN , $ event );
245251 $ input = $ event ->getInput ();
246252
247253 if (!$ name ) {
@@ -251,7 +257,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
251257 try {
252258 $ exitCode = parent ::doRun ($ input , $ output );
253259 } catch (\Exception $ e ) {
254- $ this ->dispatcher -> dispatch (PhpcrShellEvents::COMMAND_EXCEPTION , new Event \CommandExceptionEvent ($ e , $ this , $ output ));
260+ $ this ->dispatch (PhpcrShellEvents::COMMAND_EXCEPTION , new Event \CommandExceptionEvent ($ e , $ this , $ output ));
255261
256262 return 1 ;
257263 }
@@ -291,7 +297,7 @@ public function add(Command $command)
291297 public function dispatchProfileInitEvent (InputInterface $ sessionInput , OutputInterface $ output )
292298 {
293299 $ event = new Event \ProfileInitEvent ($ this ->container ->get ('config.profile ' ), $ sessionInput , $ output );
294- $ this ->dispatcher -> dispatch (PhpcrShellEvents::PROFILE_INIT , $ event );
300+ $ this ->dispatch (PhpcrShellEvents::PROFILE_INIT , $ event );
295301 }
296302
297303 /**
@@ -328,4 +334,14 @@ public function setDebug($debug)
328334 {
329335 $ this ->debug = $ debug ;
330336 }
337+
338+ private function dispatch (string $ eventName , $ event )
339+ {
340+ // LegacyEventDispatcherProxy exists in Symfony >= 4.3
341+ if (class_exists (LegacyEventDispatcherProxy::class)) {
342+ return $ this ->dispatcher ->dispatch ($ event , $ eventName );
343+ }
344+
345+ return $ this ->dispatcher ->dispatch ($ eventName , $ event );
346+ }
331347}
0 commit comments