Skip to content

Commit 7d05c61

Browse files
Upgrade for symfony/event-dispatcher 5.0
1 parent 54cc4d5 commit 7d05c61

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
lines changed

src/PHPCR/Shell/Console/Application/ShellApplication.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Symfony\Component\Console\Output\OutputInterface;
2929
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
3030
use 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
}

src/PHPCR/Shell/Event/ApplicationInitEvent.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
namespace PHPCR\Shell\Event;
1414

1515
use Symfony\Component\Console\Application;
16-
use Symfony\Component\EventDispatcher\Event;
1716

1817
/**
1918
* This event is fired when the main shell application

src/PHPCR/Shell/Event/CommandExceptionEvent.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
use PHPCR\Shell\Console\Application\ShellApplication;
1616
use Symfony\Component\Console\Output\OutputInterface;
17-
use Symfony\Component\EventDispatcher\Event;
1817

1918
class CommandExceptionEvent extends Event
2019
{

src/PHPCR/Shell/Event/CommandPreRunEvent.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
namespace PHPCR\Shell\Event;
1414

1515
use Symfony\Component\Console\Input\InputInterface;
16-
use Symfony\Component\EventDispatcher\Event;
1716

1817
class CommandPreRunEvent extends Event
1918
{

src/PHPCR/Shell/Event/Event.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Event;
4+
5+
use Symfony\Component\EventDispatcher\Event as OldEvent;
6+
use Symfony\Contracts\EventDispatcher\Event as ContractEvent;
7+
8+
if (class_exists(ContractEvent::class)) {
9+
class Event extends ContractEvent
10+
{
11+
}
12+
} else {
13+
class Event extends OldEvent
14+
{
15+
}
16+
}

src/PHPCR/Shell/Event/ProfileInitEvent.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use PHPCR\Shell\Config\Profile;
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Output\OutputInterface;
18-
use Symfony\Component\EventDispatcher\Event;
1918

2019
/**
2120
* Event that is fired when the Profile needs to be initialized.

0 commit comments

Comments
 (0)