@@ -186,57 +186,12 @@ interface and have an event method for each event it subscribes to::
186
186
187
187
For a full reference, see chapter `The Event System `_ in the Doctrine documentation.
188
188
189
- Lazy loading for Event Listeners
189
+ Performance considerations
190
190
--------------------------------
191
191
192
- One subtle difference between listeners and subscribers is that Symfony can load
193
- entity listeners lazily. This means that your listener class will only be fetched
192
+ One subtle difference between listeners and subscribers is that Symfony will load
193
+ entity listeners lazily by default as of Symfony 4.2 . This means that your listener class will only be fetched
194
194
from the service container (and thus be instantiated) once the event it is linked
195
195
to actually fires.
196
196
197
- Lazy loading might give you a slight performance improvement when your listener
198
- runs for events that rarely fire. Also, it can help you when you run into
199
- *circular dependency issues * that may occur when your listener service in turn
200
- depends on the DBAL connection.
201
-
202
- To mark a listener service as lazily loaded, just add the ``lazy `` attribute
203
- to the tag like so:
204
-
205
- .. configuration-block ::
206
-
207
- .. code-block :: yaml
208
-
209
- services :
210
- App\EventListener\SearchIndexer :
211
- tags :
212
- - { name: doctrine.event_listener, event: postPersist, lazy: true }
213
-
214
- .. code-block :: xml
215
-
216
- <?xml version =" 1.0" ?>
217
- <container xmlns =" http://symfony.com/schema/dic/services"
218
- xmlns : doctrine =" http://symfony.com/schema/dic/doctrine" >
219
-
220
- <services >
221
- <service id =" App\EventListener\SearchIndexer" autowire =" true" >
222
- <tag name =" doctrine.event_listener" event =" postPersist" lazy =" true" />
223
- </service >
224
- </services >
225
- </container >
226
-
227
- .. code-block :: php
228
-
229
- use App\EventListener\SearchIndexer;
230
-
231
- $container
232
- ->autowire(SearchIndexer::class)
233
- ->addTag('doctrine.event_listener', array('event' => 'postPersist', 'lazy' => 'true'))
234
- ;
235
-
236
- .. note ::
237
-
238
- Marking an event listener as ``lazy `` has nothing to do with lazy service
239
- definitions which are described :doc: `in their own section </service_container/lazy_services >`
240
-
241
- .. _`The Event System` : http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html
242
- .. _`the Doctrine Documentation` : http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#entity-listeners
197
+ So whenever possible it is preferable to use entity listeners instead of subscribers.
0 commit comments