Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e1b0be3

Browse filesBrowse files
committed
bug #41905 [EventDispatcher] Correct the called event listener method case (JJsty1e)
This PR was submitted for the 5.4 branch but it was squashed and merged into the 4.4 branch instead. Discussion ---------- [EventDispatcher] Correct the called event listener method case | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | none | Tickets | none | License | MIT | Doc PR | none when define an event listener, if you don't specify a method, then the word case of the actual method maybe wrong, for example : ```yaml services: my_kernel_envent_listeners: class: App\EventListener\KernelListener tags: - { name: kernel.event_listener, event: kernel.controller_arguments } ``` no `method` key at this tag, then actual method called is `onKernelControllerarguments`, actually it should be `onKernelControllerArguments`, the case of word 'arguments' should be upper. ps: only event name that has dash(`_`) will be affected. Commits ------- 29b4b76 [EventDispatcher] Correct the called event listener method case
2 parents b1cf295 + 29b4b76 commit e1b0be3
Copy full SHA for e1b0be3

File tree

2 files changed

+10
-1
lines changed
Filter options

2 files changed

+10
-1
lines changed

‎src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function process(ContainerBuilder $container)
8181

8282
if (!isset($event['method'])) {
8383
$event['method'] = 'on'.preg_replace_callback([
84-
'/(?<=\b)[a-z]/i',
84+
'/(?<=\b|_)[a-z]/i',
8585
'/[^a-z0-9]/i',
8686
], function ($matches) { return strtoupper($matches[0]); }, $event['event']);
8787
$event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']);

‎src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public function testInvokableEventListener()
175175
$container->register('foo', \stdClass::class)->addTag('kernel.event_listener', ['event' => 'foo.bar']);
176176
$container->register('bar', InvokableListenerService::class)->addTag('kernel.event_listener', ['event' => 'foo.bar']);
177177
$container->register('baz', InvokableListenerService::class)->addTag('kernel.event_listener', ['event' => 'event']);
178+
$container->register('zar', \stdClass::class)->addTag('kernel.event_listener', ['event' => 'foo.bar_zar']);
178179
$container->register('event_dispatcher', \stdClass::class);
179180

180181
$registerListenersPass = new RegisterListenersPass();
@@ -206,6 +207,14 @@ public function testInvokableEventListener()
206207
0,
207208
],
208209
],
210+
[
211+
'addListener',
212+
[
213+
'foo.bar_zar',
214+
[new ServiceClosureArgument(new Reference('zar')), 'onFooBarZar'],
215+
0,
216+
],
217+
],
209218
];
210219
$this->assertEquals($expectedCalls, $definition->getMethodCalls());
211220
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.