Skip to content

Commit f40da34

Browse files
committed
Added docs on event listeners and subscribers DIC configuration for Doctrine
1 parent eff58a0 commit f40da34

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

guides/doctrine/mongodb-odm/configuration.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,5 +294,13 @@ Later you can retrieve the persisted document by its id::
294294
}
295295
}
296296

297+
Registering Event Listeners and Subscribers
298+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
299+
300+
Registering events works like described in the :ref:`ORM Bundle documentation <doctrine-event-config>`.
301+
The MongoDB event tags are called "doctrine.odm.mongodb.default_event_listener" and
302+
"doctrine.odm.mongodb.default_event_subscriber" respectively where "default" is the name of the
303+
MongoDB document manager.
304+
297305
.. _MongoDB: http://www.mongodb.org/
298306
.. _documentation: http://www.doctrine-project.org/projects/mongodb_odm/1.0/docs/en

guides/doctrine/orm/configuration.rst

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,65 @@ retrieve it from the Symfony Dependency Injection Container::
147147

148148
The service "doctrine.orm.entity_manager" is an alias for the default entity
149149
manager defined in the "default_entity_manager" configuration option.
150+
151+
.. _doctrine-event-config:
152+
153+
Registering Event Listeners and Subscribers
154+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
155+
156+
Doctrine ships with an event system that allows to hook into many different
157+
events happening during the lifecycle of entities or at other occasions.
158+
159+
To register services to act as event listeners or subscribers (listeners from here)
160+
you have to tag them with the appropriate names. Depending on your use-case you can hook
161+
a listener into every DBAL Connection and ORM Entity Manager or just into one
162+
specific DBAL connection and all the EntityManagers that use this connection.
163+
164+
.. configuration-block::
165+
166+
.. code-block:: yaml
167+
168+
doctrine.dbal:
169+
default_connection: default
170+
connections:
171+
default:
172+
driver: pdo_sqlite
173+
memory: true
174+
175+
services:
176+
my.listener:
177+
class: MyEventListener
178+
tags:
179+
- { name: doctrine.common.event_listener }
180+
my.listener2:
181+
class: MyEventListener2
182+
tags:
183+
- { name: doctrine.dbal.default_event_listener }
184+
my.subscriber:
185+
class: MyEventSubscriber
186+
tags:
187+
- { name: doctrine.dbal.default_event_subscriber }
188+
189+
.. code-block:: xml
190+
191+
<?xml version="1.0" ?>
192+
<container xmlns="http://symfony-project.org/2.0/container"
193+
xmlns:doctrine="http://www.symfony-project.org/schema/dic/doctrine">
194+
<doctrine:dbal default-connection="default">
195+
<doctrine:connections>
196+
<doctrine:connection driver="pdo_sqlite" memory="true" />
197+
</doctrine:connections>
198+
</doctrine:dbal>
199+
200+
<services>
201+
<service id="my.listener" class="MyEventListener">
202+
<tag name="doctrine.common.event_listener" />
203+
</service>
204+
<service id="my.listener2" class="MyEventListener2">
205+
<tag name="doctrine.dbal.default_event_listener" />
206+
</service>
207+
<service id="my.subscriber" class="MyEventSubscriber">
208+
<tag name="doctrine.dbal.default_event_subscriber" />
209+
</service>
210+
</services>
211+
</container>

0 commit comments

Comments
 (0)