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_listenertag defines themethodattribute, that's the name of the method to be executed; -
If no
methodattribute is defined, try to execute the method whose name ison+ "camel-cased event name" (e.g.onKernelException()method for thekernel.exceptionevent); -
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_listenertag calledpriority, which is a positive or negative integer that defaults to0and 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-256to256but your own listeners can use any positive or negative integer.