@@ -143,9 +143,24 @@ do so, define a listener for the ``postPersist`` Doctrine event::
143
143
}
144
144
}
145
145
146
- The next step is to enable the Doctrine listener in the Symfony application by
147
- creating a new service for it and :doc: `tagging it </service_container/tags >`
148
- with the ``doctrine.event_listener `` tag:
146
+ Then, add the ``#[AsDoctrineListener] `` attribute to the class to enable it as
147
+ a Doctrine listener in your application::
148
+
149
+ // src/EventListener/SearchIndexer.php
150
+ namespace App\EventListener;
151
+
152
+ use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
153
+ use Doctrine\ORM\Events;
154
+
155
+ #[AsDoctrineListener(event: Events::postPersist, priority: 500, connection: 'default')]
156
+ class SearchIndexer
157
+ {
158
+ // ...
159
+ }
160
+
161
+ Alternatively, if you prefer to not use PHP attributes, you mustenable the Doctrine listener in the Symfony application by creating a new
162
+ service for it and :doc: `tagging it </service_container/tags >` with
163
+ the ``doctrine.event_listener `` tag:
149
164
150
165
.. configuration-block ::
151
166
@@ -272,7 +287,7 @@ a Doctrine entity listener in your application::
272
287
// ...
273
288
}
274
289
275
- That's it. Alternatively, if you prefer to not use PHP attributes, you must
290
+ Alternatively, if you prefer to not use PHP attributes, you must
276
291
configure a service for the entity listener and :doc: `tag it </service_container/tags >`
277
292
with the ``doctrine.orm.entity_listener `` tag as follows:
278
293
0 commit comments