I have defined 2 event listeners for "name: kernel.event_listener, event: kernel.request", but I can do what I want, I can't change the order of calling this listener. I try to use the "priority" number, but nothing helps.
This event is always calling @first:
MyBundle.Foo.Listener.RequestListener:
class: %MyBundle.Foo.Listener.request.class%
arguments: [ @session, @liip_theme.active_theme, @Need.some.infos.service ]
tags:
- { name: kernel.event_listener, event: kernel.request, method: onRequest, priority: 100 }
and this event is never calling, because the first event use a service that depends on a info of this event, so it crashes before this event is triggered:
MyBundle.Bar.Listener.RequestListener:
class: %MyBundle.Bar.Listener.request.class%
arguments: [ @session ]
tags:
- { name: kernel.event_listener, event: kernel.request, method: onRequest, priority: 200 }
I have changed the "priority" too, but nothing changed :(
Maybe someone have a tip for me, that I can to ensure that listener "MyBundle.Bar.Listener.RequestListener" will call before the other event?
The problem is that the event listener class will init at Symfony start, before any event triggers.
I had to change my DI to:
MyBundle.Foo.Listener.RequestListener:
class: %MyBundle.Foo.Listener.request.class%
arguments: [ @session, @liip_theme.active_theme, @service_container ]
tags:
- { name: kernel.event_listener, event: kernel.request, method: onRequest, priority: 0 }
I used this "@service_container" service, and call inside the event the target service "@Need.some.infos.service" and all works fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With