Skip to content

Commit bc4df88

Browse files
committed
bug #552 Fixing bug where passing the full class name as the event didn't return same string (weaverryan)
This PR was merged into the 1.0-dev branch. Discussion ---------- Fixing bug where passing the full class name as the event didn't return same string This caused an undefined index when running `make:subscriber` and choosing a fully-qualified event class as your event string. In this case, `EventRegistry::getEventClassName()` really has no work to do. Commits ------- 841a92c Fixing bug where passing the full class name as the event didn't return that same string
2 parents 4c44601 + 841a92c commit bc4df88

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/EventRegistry.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ public function getAllActiveEvents(): array
125125
*/
126126
public function getEventClassName(string $event)
127127
{
128+
// if the event is already a class name, use it
129+
if (class_exists($event)) {
130+
return $event;
131+
}
132+
128133
if (isset(self::$eventsMap[$event])) {
129134
return self::$eventsMap[$event];
130135
}

tests/EventRegistryTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\MakerBundle\EventRegistry;
1616
use Symfony\Component\Console\Event\ConsoleCommandEvent;
1717
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
18+
use Symfony\Component\HttpKernel\Event\ControllerEvent;
1819
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
1920
use Symfony\Component\HttpKernel\KernelEvents;
2021

@@ -84,6 +85,14 @@ public function testGetNewEventClassNameFromStandardList()
8485
$registry = new EventRegistry($dispatcher);
8586
$this->assertSame(ExceptionEvent::class, $registry->getEventClassName(KernelEvents::EXCEPTION));
8687
}
88+
89+
public function testGetEventClassNameGivenEventAsClass()
90+
{
91+
$dispatcher = $this->createMock(EventDispatcherInterface::class);
92+
93+
$registry = new EventRegistry($dispatcher);
94+
$this->assertSame(ControllerEvent::class, $registry->getEventClassName(ControllerEvent::class));
95+
}
8796
}
8897

8998
class DummyEvent

0 commit comments

Comments
 (0)