In regard to this question, the official Symfony documentation states:
Symfony follows this logic to decide which method to execute inside the event listener class:
-
If the
kernel.event_listener
tag defines themethod
attribute, that's the name of the method to be executed; -
If no
method
attribute is defined, try to execute the method whose name ison
+ "camel-cased event name" (e.g.onKernelException()
method for thekernel.exception
event); -
If that method is not defined either, try to execute the
__invoke()
magic method (which makes event listeners invokable); -
If the
_invoke()
method is not defined either, throw an exception.
There is an optional attribute for the
kernel.event_listener
tag calledpriority
, which is a positive or negative integer that defaults to0
and it controls the order in which listeners are executed (the higher the number, 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-256
to256
but your own listeners can use any positive or negative integer.