diff --git a/src/EventRegistry.php b/src/EventRegistry.php index 7c4a5f64c..3231f9c7f 100644 --- a/src/EventRegistry.php +++ b/src/EventRegistry.php @@ -125,6 +125,11 @@ public function getAllActiveEvents(): array */ public function getEventClassName(string $event) { + // if the event is already a class name, use it + if (class_exists($event)) { + return $event; + } + if (isset(self::$eventsMap[$event])) { return self::$eventsMap[$event]; } diff --git a/tests/EventRegistryTest.php b/tests/EventRegistryTest.php index 139da0c10..5326d622a 100644 --- a/tests/EventRegistryTest.php +++ b/tests/EventRegistryTest.php @@ -15,6 +15,7 @@ use Symfony\Bundle\MakerBundle\EventRegistry; use Symfony\Component\Console\Event\ConsoleCommandEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\KernelEvents; @@ -84,6 +85,14 @@ public function testGetNewEventClassNameFromStandardList() $registry = new EventRegistry($dispatcher); $this->assertSame(ExceptionEvent::class, $registry->getEventClassName(KernelEvents::EXCEPTION)); } + + public function testGetEventClassNameGivenEventAsClass() + { + $dispatcher = $this->createMock(EventDispatcherInterface::class); + + $registry = new EventRegistry($dispatcher); + $this->assertSame(ControllerEvent::class, $registry->getEventClassName(ControllerEvent::class)); + } } class DummyEvent