From 29b4b7641609f6010ae63fae25df16c15e3edf79 Mon Sep 17 00:00:00 2001 From: jaggle Date: Tue, 29 Jun 2021 23:55:19 +0800 Subject: [PATCH] [EventDispatcher] Correct the called event listener method case --- .../DependencyInjection/RegisterListenersPass.php | 2 +- .../DependencyInjection/RegisterListenersPassTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php index 1a52c3e865..1c4e12ec86 100644 --- a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php +++ b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php @@ -81,7 +81,7 @@ class RegisterListenersPass implements CompilerPassInterface if (!isset($event['method'])) { $event['method'] = 'on'.preg_replace_callback([ - '/(?<=\b)[a-z]/i', + '/(?<=\b|_)[a-z]/i', '/[^a-z0-9]/i', ], function ($matches) { return strtoupper($matches[0]); }, $event['event']); $event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']); diff --git a/src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php b/src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php index c4623bdbcb..e0afe2c72b 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php @@ -175,6 +175,7 @@ class RegisterListenersPassTest extends TestCase $container->register('foo', \stdClass::class)->addTag('kernel.event_listener', ['event' => 'foo.bar']); $container->register('bar', InvokableListenerService::class)->addTag('kernel.event_listener', ['event' => 'foo.bar']); $container->register('baz', InvokableListenerService::class)->addTag('kernel.event_listener', ['event' => 'event']); + $container->register('zar', \stdClass::class)->addTag('kernel.event_listener', ['event' => 'foo.bar_zar']); $container->register('event_dispatcher', \stdClass::class); $registerListenersPass = new RegisterListenersPass(); @@ -206,6 +207,14 @@ class RegisterListenersPassTest extends TestCase 0, ], ], + [ + 'addListener', + [ + 'foo.bar_zar', + [new ServiceClosureArgument(new Reference('zar')), 'onFooBarZar'], + 0, + ], + ], ]; $this->assertEquals($expectedCalls, $definition->getMethodCalls()); }