@@ -107,19 +107,31 @@ using a special "tag":
107
107
->addTag('kernel.event_listener', array('event' => 'kernel.exception'))
108
108
;
109
109
110
+ Symfony follows this logic to decide which method to execute inside the event
111
+ listener class:
112
+
113
+ #. If the ``kernel.event_listener `` tag defines the ``method `` attribute, that's
114
+ the name of the method to be executed;
115
+ #. If no ``method `` attribute is defined, try to execute the method whose name
116
+ is ``on `` + "camel-cased event name" (e.g. ``onKernelException() `` method for
117
+ the ``kernel.exception `` event);
118
+ #. If that method is not defined either, try to execute the ``__invoke() `` magic
119
+ method (which makes event listeners invokable);
120
+ #. If the ``_invoke() `` method is not defined either, throw an exception.
121
+
122
+ .. versionadded :: 4.1
123
+ The support of the ``__invoke() `` method to create invokable event listeners
124
+ was introduced in Symfony 4.1.
125
+
110
126
.. note ::
111
127
112
- There is an optional tag attribute called ``method `` which defines which method
113
- to execute when the event is triggered. By default the name of the method is
114
- ``on `` + "camel-cased event name". If the event is ``kernel.exception `` the
115
- method executed by default is ``onKernelException() ``.
116
-
117
- The other optional tag attribute is called ``priority ``, which defaults to
118
- ``0 `` and it controls the order in which listeners are executed (the highest
119
- the priority, the earlier a listener is executed). This is useful when you
120
- need to guarantee that one listener is executed before another. The priorities
121
- of the internal Symfony listeners usually range from ``-255 `` to ``255 `` but
122
- your own listeners can use any positive or negative integer.
128
+ There is an optional attribute for the ``kernel.event_listener `` tag called
129
+ ``priority ``, which defaults to ``0 `` and it controls the order in which
130
+ listeners are executed (the highest the priority, the earlier a listener is
131
+ executed). This is useful when you need to guarantee that one listener is
132
+ executed before another. The priorities of the internal Symfony listeners
133
+ usually range from ``-255 `` to ``255 `` but your own listeners can use any
134
+ positive or negative integer.
123
135
124
136
.. _events-subscriber :
125
137
0 commit comments