Fix register event listeners compiler pass
This commit is contained in:
parent
b4342e3a9b
commit
646878d072
@ -56,12 +56,12 @@ class RegisterListenersPass implements CompilerPassInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$aliases = [];
|
||||||
|
|
||||||
if ($container->hasParameter($this->eventAliasesParameter)) {
|
if ($container->hasParameter($this->eventAliasesParameter)) {
|
||||||
$aliases = $container->getParameter($this->eventAliasesParameter);
|
$aliases = $container->getParameter($this->eventAliasesParameter);
|
||||||
$container->getParameterBag()->remove($this->eventAliasesParameter);
|
|
||||||
} else {
|
|
||||||
$aliases = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$definition = $container->findDefinition($this->dispatcherService);
|
$definition = $container->findDefinition($this->dispatcherService);
|
||||||
|
|
||||||
foreach ($container->findTaggedServiceIds($this->listenerTag, true) as $id => $events) {
|
foreach ($container->findTaggedServiceIds($this->listenerTag, true) as $id => $events) {
|
||||||
|
@ -213,17 +213,22 @@ class RegisterListenersPassTest extends TestCase
|
|||||||
public function testAliasedEventListener(): void
|
public function testAliasedEventListener(): void
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
$container->setParameter('event_dispatcher.event_aliases', [AliasedEvent::class => 'aliased_event']);
|
$eventAliases = [AliasedEvent::class => 'aliased_event'];
|
||||||
|
$container->setParameter('event_dispatcher.event_aliases', $eventAliases);
|
||||||
$container->register('foo', InvokableListenerService::class)->addTag('kernel.event_listener', ['event' => AliasedEvent::class, 'method' => 'onEvent']);
|
$container->register('foo', InvokableListenerService::class)->addTag('kernel.event_listener', ['event' => AliasedEvent::class, 'method' => 'onEvent']);
|
||||||
$container->register('bar', InvokableListenerService::class)->addTag('kernel.event_listener', ['event' => CustomEvent::class, 'method' => 'onEvent']);
|
$container->register('bar', InvokableListenerService::class)->addTag('kernel.event_listener', ['event' => CustomEvent::class, 'method' => 'onEvent']);
|
||||||
$container->register('event_dispatcher');
|
$container->register('event_dispatcher');
|
||||||
|
|
||||||
$eventAliasPass = new AddEventAliasesPass([CustomEvent::class => 'custom_event']);
|
$customEventAlias = [CustomEvent::class => 'custom_event'];
|
||||||
|
$eventAliasPass = new AddEventAliasesPass($customEventAlias);
|
||||||
$eventAliasPass->process($container);
|
$eventAliasPass->process($container);
|
||||||
|
|
||||||
$registerListenersPass = new RegisterListenersPass();
|
$registerListenersPass = new RegisterListenersPass();
|
||||||
$registerListenersPass->process($container);
|
$registerListenersPass->process($container);
|
||||||
|
|
||||||
|
$this->assertTrue($container->hasParameter('event_dispatcher.event_aliases'));
|
||||||
|
$this->assertSame(array_merge($eventAliases, $customEventAlias), $container->getParameter('event_dispatcher.event_aliases'));
|
||||||
|
|
||||||
$definition = $container->getDefinition('event_dispatcher');
|
$definition = $container->getDefinition('event_dispatcher');
|
||||||
$expectedCalls = [
|
$expectedCalls = [
|
||||||
[
|
[
|
||||||
|
Reference in New Issue
Block a user