migrations icon indicating copy to clipboard operation
migrations copied to clipboard

DependencyFactory::getEventDispatcher triggers a deprecation

Open VincentLanglet opened this issue 2 years ago • 6 comments

Bug Report

Q A
BC Break no
Version x.y.z

Summary

DependencyFactory::getEventDispatcher is implemented this way:

return $this->getDependency(EventDispatcher::class, function (): EventDispatcher {
    return new EventDispatcher(
        $this->getConnection(),
        $this->getConnection()->getEventManager(),
    );
});

but Connection::getEventManager is deprecated by dbal since https://github.com/doctrine/dbal/issues/5784

Not sure how to fix this @greg0ire @derrabus

VincentLanglet avatar Aug 11 '23 08:08 VincentLanglet

Deprecate calling fromConnection() without passing an event manager?

derrabus avatar Aug 11 '23 08:08 derrabus

Seems like EntityManagerInterface::getEventManager exists ; I'll try this instead.

VincentLanglet avatar Aug 11 '23 08:08 VincentLanglet

Seems like EntityManagerInterface::getEventManager exists ; I'll try this instead.

Yes, but that'll only work if you have an entity manager. You can use migrations with a connection only.

derrabus avatar Aug 11 '23 09:08 derrabus

fromConnection should indeed allow passing an EventManager explicitly, using Connection::getEventManager only as fallback (triggering a deprecation telling you to pass an EventManager explicitly). fromEntityManager would register the EventManager using the ORM EventManager.

DependencyFactory::getEventDispatcher would then use a DependencyFactory::getEventManager method reading the configured event manager.

stof avatar Aug 11 '23 09:08 stof

DoctrineCommand is doing DependencyFactory::fromConnection does it mean we have to add EventManager to the constructor of all doctrine command ?

VincentLanglet avatar Aug 11 '23 13:08 VincentLanglet

To be compatible with CLI commands, we might need a concept of an event manager loader instead of passing directly an event manager.

stof avatar Aug 11 '23 13:08 stof