Skip to content
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

Simplify the event registration #1125

Merged
merged 4 commits into from Dec 23, 2019
Merged

Simplify the event registration #1125

merged 4 commits into from Dec 23, 2019

Conversation

leofeyer
Copy link
Member

@leofeyer leofeyer added this to the 4.9 milestone Dec 20, 2019
@leofeyer leofeyer self-assigned this Dec 20, 2019
Copy link
Member

@Toflar Toflar left a comment

Choose a reason for hiding this comment

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

LGTM at first sight. Can you explain why some of them still require the event: kernel.request or event: kernel.response tag?

@leofeyer
Copy link
Member Author

leofeyer commented Dec 23, 2019

You mean something like this, right?

- { name: kernel.event_listener, event: kernel.request, priority: 255 }
- { name: kernel.event_listener, event: kernel.response, priority: -255 }

I don't think there is a way to assign two different priorities to two different events without keeping the event: key, is there?

- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 36 }
- { name: kernel.event_listener, event: kernel.response, method: onKernelResponse }
- { name: kernel.event_listener, event: kernel.request, priority: 36 }
- { name: kernel.event_listener, event: kernel.response }
Copy link
Member

Choose a reason for hiding this comment

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

This for example, why is event: kernel.response still required here? There's no priority attribute.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because otherwise Symfony throws an exception: Service "contao.listener.csrf_token_cookie" must define the "event" attribute on "kernel.event_listener" tags. 🤷‍♂

Copy link
Member

Choose a reason for hiding this comment

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

Okay, but why? 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know. But three remaining event: keys should not prevent us from merging this PR.

Copy link
Member

Choose a reason for hiding this comment

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

I'm reviewing here and I would like to understand why it doesn't work so that we can either fix it or know why we have inconsistency now. Can you check which condition of RegisterListenersPass::getEventFromTypeDeclaration() is failing?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have found the issue. The pass is looking for an __invoke() method and if there is none, you either have to specify the event or method key. If no method key is given, it is computed from the event key.

I guess it is more correct to specify the method names in our three cases (see 4a95e51).

Copy link
Member

Choose a reason for hiding this comment

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

I guess it is more correct to specify the method names in our three cases (see 4a95e51).

I agree with that 👍

@leofeyer
Copy link
Member Author

I went through all definitions with an event: key in their tags again and I was able to get rid of one more in a9e2e7f. The remaining ones cannot be removed without Symfony throwing an exception.

@leofeyer leofeyer merged commit e6c7ca3 into master Dec 23, 2019
@leofeyer leofeyer deleted the feature/event-registration branch December 23, 2019 15:25
leofeyer pushed a commit that referenced this pull request Dec 23, 2019
Description
-----------

Changed method signature in #1125.

Commits
-------

4387e96 Renamed method after changing its signature
@leofeyer leofeyer mentioned this pull request Jan 6, 2020
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants