doctrine / migrations

Doctrine Database Migrations Library
https://www.doctrine-project.org/projects/migrations.html
MIT License
4.68k stars 385 forks source link

DependencyFactory::getEventDispatcher triggers a deprecation #1348

Open VincentLanglet opened 1 year ago

VincentLanglet commented 1 year ago

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

derrabus commented 1 year ago

Deprecate calling fromConnection() without passing an event manager?

VincentLanglet commented 1 year ago

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

derrabus commented 1 year ago

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.

stof commented 1 year ago

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.

VincentLanglet commented 1 year ago

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

stof commented 1 year ago

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