I have a Symfony 3.4 app and a Composer package with an EntityChangeListener to log entity property changes. The package also contains a EntityListenerPass (compiler pass) which iterates over a list of class names defined in app config.yml while building the service container. It programmatically tags the entity classes like this to notify the listener on preUpdate events:
$listener = $container->getDefinition('entity_history.listener.entity_change');
$entities = $container->getExtensionConfig('entity_history')[0]['entities'];
foreach ($entities as $className) {
$listener->addTag('doctrine.orm.entity_listener', ['entity' => $className, 'event' => 'preUpdate']);
}
Adding those tags causes a lot of errors which appear unrelated. In example undefined index errors inside the Doctrine UnitOfWork for the entity states. Also related entities which are loaded from database suddenly are recognised as new by Doctrine. Even object comparison inside a switch statement started to fail with:
Fatal error: Nesting level too deep - recursive dependency?
But without those listeners, everything works fine and all tests pass. Is there an alternative/better way to programmatically set up Doctrine entity listeners?
EntityChangeListener?EntityChangeListenerthis is some bundle ? Because I did not find this in git