@@ -143,9 +143,24 @@ do so, define a listener for the ``postPersist`` Doctrine event::
143143 }
144144 }
145145
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:
149164
150165.. configuration-block ::
151166
@@ -272,7 +287,7 @@ a Doctrine entity listener in your application::
272287 // ...
273288 }
274289
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
276291configure a service for the entity listener and :doc: `tag it </service_container/tags >`
277292with the ``doctrine.orm.entity_listener `` tag as follows:
278293
0 commit comments