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

[EventDispatcher] Correct the called event listener method case #41905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2021

Conversation

jjsty1e
Copy link
Contributor

@jjsty1e jjsty1e commented Jun 29, 2021

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 :

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.

@jjsty1e
Copy link
Contributor Author

jjsty1e commented Jun 29, 2021

sorry, it seems this PR should be filed to branch 4.4

@jjsty1e
Copy link
Contributor Author

jjsty1e commented Jun 30, 2021

failed tests😭, so hard to make a pull request, but problem indeed exists

@derrabus derrabus added this to the 4.4 milestone Jun 30, 2021
@derrabus
Copy link
Member

The current behavior might be somewhat unexpected. But if we just change it, we will break existing applications. Can we make it so that both ways work?

@fabpot
Copy link
Member

fabpot commented Jun 30, 2021

Method names are case insentitive in PHP, right? So, is there a bug that needs to fix here or is it just for a better looking method name?

@derrabus
Copy link
Member

Method names are case insentitive in PHP, right?

If we don't configure a method name, RegisterListenersPass will guess it. And that logic is case-sensitive.

So, is there a bug that needs to fix here or is it just for a better looking method name?

It's about allowing a less surprising method name, I'd say.

@derrabus derrabus added the DX DX = Developer eXperience (anything that improves the experience of using Symfony) label Jun 30, 2021
@ro0NL
Copy link
Contributor

ro0NL commented Jun 30, 2021

Ref #41876

Copy link
Contributor

@ro0NL ro0NL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@ro0NL ro0NL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tend to believe it's a bugfix (as method calls are case-insensitive). Camel casing at every word boundary, but not _, feels odd

ppl relying on case-sensitive method calls in DI config (which now changes) rely on implementation details IMHO. But 5.x would be as fine i guess 👍

@jjsty1e how did you discovered this? :D

@@ -81,7 +81,7 @@ public function process(ContainerBuilder $container)

if (!isset($event['method'])) {
$event['method'] = 'on'.preg_replace_callback([
'/(?<=\b)[a-z]/i',
'/(?<=\b|_)[a-z]/i',
'/[^a-z0-9]/i',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw this 2nd regex is a leftover from https://github.com/symfony/symfony/pull/1162/files it seems, where it was replaced with empty string which now happens at L87, this happened with refactoring likely.

AFAIK it's redundant 👼

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it confused me too, but I'm not sure we can remove

@jjsty1e
Copy link
Contributor Author

jjsty1e commented Jul 3, 2021

@jjsty1e how did you discovered this? :D

when do some breakpoint debugging in my project.

@nicolas-grekas
Copy link
Member

please apply the code style fix from fabbot

@fabpot fabpot changed the base branch from 5.4 to 4.4 July 4, 2021 09:02
@fabpot
Copy link
Member

fabpot commented Jul 4, 2021

Thank you @jjsty1e.

@fabpot fabpot merged commit e1b0be3 into symfony:4.4 Jul 4, 2021
@jjsty1e
Copy link
Contributor Author

jjsty1e commented Jul 4, 2021

@fabpot my pleasure😀

@jjsty1e jjsty1e deleted the patch1 branch July 4, 2021 17:39
This was referenced Jul 26, 2021
@fabpot fabpot mentioned this pull request Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug DX DX = Developer eXperience (anything that improves the experience of using Symfony) EventDispatcher Status: Reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.