migrations
migrations copied to clipboard
DependencyFactory::getEventDispatcher triggers a deprecation
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
Deprecate calling fromConnection() without passing an event manager?
Seems like EntityManagerInterface::getEventManager exists ; I'll try this instead.
Seems like
EntityManagerInterface::getEventManagerexists ; 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.
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.
DoctrineCommand is doing DependencyFactory::fromConnection does it mean we have to add EventManager to the constructor of all doctrine command ?
To be compatible with CLI commands, we might need a concept of an event manager loader instead of passing directly an event manager.