Skip to content

Commit 91def16

Browse files
[EventDispatcher] swap arguments of dispatch() to allow registering events by FQCN
1 parent 122a9f0 commit 91def16

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

Application.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use Symfony\Component\Debug\ErrorHandler;
4545
use Symfony\Component\Debug\Exception\FatalThrowableError;
4646
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
47+
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
4748

4849
/**
4950
* An Application is the container for a collection of commands.
@@ -92,7 +93,7 @@ public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN
9293

9394
public function setDispatcher(EventDispatcherInterface $dispatcher)
9495
{
95-
$this->dispatcher = $dispatcher;
96+
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
9697
}
9798

9899
public function setCommandLoader(CommandLoaderInterface $commandLoader)
@@ -235,7 +236,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
235236
if (!($e instanceof CommandNotFoundException && !$e instanceof NamespaceNotFoundException) || 1 !== \count($alternatives = $e->getAlternatives()) || !$input->isInteractive()) {
236237
if (null !== $this->dispatcher) {
237238
$event = new ConsoleErrorEvent($input, $output, $e);
238-
$this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
239+
$this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
239240

240241
if (0 === $event->getExitCode()) {
241242
return 0;
@@ -254,7 +255,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
254255
if (!$style->confirm(sprintf('Do you want to run "%s" instead? ', $alternative), false)) {
255256
if (null !== $this->dispatcher) {
256257
$event = new ConsoleErrorEvent($input, $output, $e);
257-
$this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
258+
$this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
258259

259260
return $event->getExitCode();
260261
}
@@ -920,7 +921,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
920921
$e = null;
921922

922923
try {
923-
$this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
924+
$this->dispatcher->dispatch($event, ConsoleEvents::COMMAND);
924925

925926
if ($event->commandShouldRun()) {
926927
$exitCode = $command->run($input, $output);
@@ -929,7 +930,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
929930
}
930931
} catch (\Throwable $e) {
931932
$event = new ConsoleErrorEvent($input, $output, $e, $command);
932-
$this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
933+
$this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
933934
$e = $event->getError();
934935

935936
if (0 === $exitCode = $event->getExitCode()) {
@@ -938,7 +939,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
938939
}
939940

940941
$event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
941-
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
942+
$this->dispatcher->dispatch($event, ConsoleEvents::TERMINATE);
942943

943944
if (null !== $e) {
944945
throw $e;

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"require-dev": {
2525
"symfony/config": "~3.4|~4.0",
26-
"symfony/event-dispatcher": "~3.4|~4.0",
26+
"symfony/event-dispatcher": "^4.3",
2727
"symfony/dependency-injection": "~3.4|~4.0",
2828
"symfony/lock": "~3.4|~4.0",
2929
"symfony/process": "~3.4|~4.0",
@@ -40,6 +40,7 @@
4040
},
4141
"conflict": {
4242
"symfony/dependency-injection": "<3.4",
43+
"symfony/event-dispatcher": "<4.3",
4344
"symfony/process": "<3.3"
4445
},
4546
"autoload": {

0 commit comments

Comments
 (0)