Here is my service.yml :
services:
foo.builder:
class: MyBundle\Core\MyClass
foo.twig_extension:
class: MyBundle\Twig\BarExtension
arguments: ['@foo.builder']
tags:
- { name: twig.extension }
foo.listener.foolistener:
class: MyBundle\EventListener\MyListener
arguments: ['@service_container']
tags:
- { name: kernel.event_listener, event: kernel.controller, method: createFooObject }
My listener always start before my twig extensions and it's good, but not just after clear the cache... My app is always crashing the first time (after clearing the cache or change the parameters) because my twig extension needs to have an object already hydrated by the listener. So if it start before, it normally crash :(
1/ what is the problem ?
2/ how can i force my listener to start always before twig extension ?
Any suggestions will be welcome
Event listeners page reads:
The other optional tag attribute is called
priority
, which defaults to 0 and it controls the order in which listeners are executed (the highest the priority, the earlier a listener is executed). This is useful when you need to guarantee that one listener is executed before another. The priorities of the internal Symfony listeners usually range from-255
to255
but your own listeners can use any positive or negative integer.
List your listeners and their priorities with command:
php app(or bin)/console debug:event-dispatcher
and assign appropriate priority
to it like below. Update priority: 0
. If you don't set it at all, the priority value defaults to 0
.
- { name: kernel.whatever, event: kernel.whatever, method: whatever, priority: 0 }