Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb8a7564

Browse files
committed
minor#9973 [DoctrineBridge] update doctrine event listeners doc for Symfony 4.2 change (dmaicher, javiereguiluz)
This PR was merged into the master branch.Discussion----------[DoctrineBridge] update doctrine event listeners doc for Symfony 4.2 changeSeesymfony/symfony#27675.Doctrine entity listeners are always lazily instantiated as of Symfony 4.2.Commits-------4409fd6 Explain that lazy listeners are mandatory, not defaultb56ef9e Update event_listeners_subscribers.rstd8bb849 Reworded and added the versionadded directive601450e Update event_listeners_subscribers.rst
2 parentsf5e8ac9 +4409fd6 commitb8a7564

File tree

1 file changed

+11
-51
lines changed

1 file changed

+11
-51
lines changed

‎doctrine/event_listeners_subscribers.rst‎

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -186,57 +186,17 @@ interface and have an event method for each event it subscribes to::
186186

187187
For a full reference, see chapter `The Event System`_ in the Doctrine documentation.
188188

189-
Lazy loading for Event Listeners
190-
--------------------------------
189+
Performance Considerations
190+
--------------------------
191191

192-
Onesubtle difference between listeners and subscribers is that Symfonycan load
193-
entity listeners lazily. This means thatyour listenerclass will only be fetched
194-
from the service container (andthus beinstantiated)once the eventitislinked
195-
to actually fires.
192+
Oneimportant difference between listeners and subscribers is that Symfonyloads
193+
entity listeners lazily. This means thatthe listenerclasses are only fetched
194+
from the service container (and instantiated)if therelatedevent isactually
195+
fired.
196196

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.
197+
That's why it is preferable to use entity listeners instead of subscribers
198+
whenever possible.
201199

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-
<containerxmlns="http://symfony.com/schema/dic/services"
218-
xmlns:doctrine="http://symfony.com/schema/dic/doctrine">
219-
220-
<services>
221-
<serviceid="App\EventListener\SearchIndexer"autowire="true">
222-
<tagname="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
200+
..versionadded::4.2
201+
Starting from Symfony 4.2, Doctrine entity listeners are always lazy. In
202+
previous Symfony versions this behavior was configurable.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp