doctrine / DoctrineMongoDBBundle

Integrates Doctrine MongoDB ODM with Symfony
http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html
MIT License
379 stars 229 forks source link

add AsDocumentListener attribute #715

Closed IonBazan closed 2 years ago

IonBazan commented 2 years ago

This PR adds AsDocumentListener attribute which adds doctrine_mongodb.odm.event_listener tag to the service.

Depends on #716 as using attributes in DI requires class to be found in order to use Reflection.

malarzm commented 2 years ago

I'm prolly missing something, but how is this different from https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/2.2/reference/events.html#lifecycle-callbacks?

IonBazan commented 2 years ago

@malarzm this is just a way to register an EventListener without touching services.yaml - instead of tagging the service there, you can add an attribute to the class. This mirrors the ORM's feature: https://github.com/doctrine/DoctrineBundle/pull/1345 and uses Symfony 5.3 feature: https://symfony.com/blog/new-in-symfony-5-3-service-autoconfiguration-and-attributes

malarzm commented 2 years ago

Ah cool, somehow I thought I saw in PR #AsDocumentListener on a document class and thought about lifecycle callbacks. Must have been late, sorry ^^