Description
Symfony version(s) affected: 4.2.5
Description
If some listeners are removed from ContainerAwareEventManager
before being initialized they can not be added back if any event was dispatched in the meantime. This happens because dispatchEvent
marks specific groups of events as initialized BUT addEventListener
checks whether anything was intialized
Possible Solution
Maybe if a listeners is a string the container should be always checked whether it has a service defined under that name? That should allow adding lazy loaded listeners after construction. Other option might be to initialize listeners in getListeners
but I don't know how it is used internally by Symfony.
Additional context
In our app we're disabling and re-enabling Doctrine events mostly to disable FosElastica events for batch operations. This is no longer possible.