Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DoctrineBundle] deprecate EventSubscriberInterface #1664

Conversation

alli83
Copy link
Contributor

@alli83 alli83 commented May 26, 2023

Doctrine subscribers are flawed because they force eager loading by design so the goal since symfony/symfony#49918 and #1650 is to push projects to use attributes to register their listeners through autoconfiguration. In order to achieve this goal, this PR propose to deprecate the EventSubscriberInterface available in doctrine/doctrine-bundle.

EventSubscriber/EventSubscriberInterface.php Outdated Show resolved Hide resolved
EventSubscriber/EventSubscriberInterface.php Outdated Show resolved Hide resolved
UPGRADE-2.10.md Outdated Show resolved Hide resolved
UPGRADE-2.10.md Outdated Show resolved Hide resolved
@alli83 alli83 force-pushed the doctrine-bundle-deprecate-event-subscriber-interface branch 2 times, most recently from f378290 to a62d7df Compare May 26, 2023 08:51
@alli83 alli83 force-pushed the doctrine-bundle-deprecate-event-subscriber-interface branch from a62d7df to 9c11976 Compare May 26, 2023 11:48
@alli83 alli83 force-pushed the doctrine-bundle-deprecate-event-subscriber-interface branch from 9c11976 to a24a1c3 Compare May 26, 2023 11:52
@ostrolucky ostrolucky added this to the 2.10.0 milestone May 27, 2023
@ostrolucky ostrolucky merged commit 656beec into doctrine:2.10.x May 27, 2023
12 checks passed
@qdequippe
Copy link

Hi,

I have the following use case that I needs in one subscriber to listen to multiple events at once

class MySubscriber implements EventSubscriberInterface
{
    ...

    public function getSubscribedEvents(): array
    {
        return array(
            Events::postUpdate,
            Events::preUpdate,
            Events::postLoad,
            Events::onFlush,
            Events::preFlush,
            Events::postFlush,
        );
    }
}

Do I need to declare 6 attributes #[AsDoctrineListener(event: Events::postPersist)], #[AsDoctrineListener(event: Events::preFlush)] ... to remove the deprecation and resolve my use case?

suggestion: what about create attribute #[AsDoctrineSubscriber]?

Regards

@ostrolucky
Copy link
Member

Yes, define 6 attributes, I don't see the issue.

@qdequippe
Copy link

Yes, define 6 attributes, I don't see the issue.

No issue just a question (and suggestion for lazy ones like me 😄)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants