doctrine / DoctrineMongoDBBundle

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

Deprecate `EventSubscriberInterface` in favor of `#[AsDocumentListener]` #817

Closed GromNaN closed 6 months ago

GromNaN commented 6 months ago

Same as https://github.com/doctrine/DoctrineBundle/pull/1664.

Fix https://github.com/doctrine/DoctrineMongoDBBundle/issues/816

I rewrote the documentation, by merging DoctrineBundle event doc and the good parts of this bundle doc. All mentions to the EventSubscriberInterface have been removed.

franmomu commented 6 months ago

I remember that #[AsDocumentListener] was introduced to mirror #[AsEntityListener], is that the same thing? I cannot check it now 😞

GromNaN commented 6 months ago

It's called AsDoctrineListener in DoctrineBundle (it was renamed). That's exactly the same feature.

franmomu commented 6 months ago

It's called AsDoctrineListener in DoctrineBundle (it was renamed). That's exactly the same feature.

What I meant is that there are two of them:

Seems like #[AsDocumentListener] was created to mirror the second one (not the renamed one which was #[AsEventListener]), but there is no similar implementation to EntityListenerPass, so I'm not sure if the $method and $lazy parameters are used here.

GromNaN commented 6 months ago

Thanks for your reviews. I discovered this feature last night, I'm going to revisit it with a more awake eye.

GromNaN commented 6 months ago

It seems that DoctrineMongoDBBundle diverged from DoctrineBundle.

RegisterEventListenersAndSubscribersPass is registered

The respective EventSubscriberInterface autoconfigure:

#[AsDoctrineListener] configure the tag doctrine.event_listener in DoctrineBundle #[AsEntityListener] configure the tag doctrine.orm.entity_listener in DoctrineBundle #[AsDocumentListener]configure the tag doctrine_mongodb.odm.event_subscriber in DoctrineMongoDBBundle

I conclude that DoctrineMongoDBBundle\AsDocumentListener equivalent to DoctrineBundle\AsDoctrineListener

GromNaN commented 6 months ago

On the #[AsDocumentListener] class, the supported parameters should be the same as #[AsDoctrineListener].

I'm thinking we should rename the class AsDocumentListener to AsDoctrineListener, to be clear. That would solve the incorrect deprecation message in the bridge: https://github.com/doctrine/DoctrineMongoDBBundle/issues/816

franmomu commented 6 months ago

Thanks for taking a look at this!

GromNaN commented 6 months ago

@franmomu @malarzm do you agree with the deprecation and doc change?