Skip to content

Commit

Permalink
Register doctrine listeners instead of subscribers
Browse files Browse the repository at this point in the history
symfony/doctrine-bridge 6.3 deprecates registering subscribers because
they are incompatible with lazy-loading.
  • Loading branch information
stof committed Jul 6, 2023
1 parent 48f0746 commit c397959
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions DependencyInjection/FOSUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ class FOSUserExtension extends Extension
private static $doctrineDrivers = [
'orm' => [
'registry' => 'doctrine',
'tag' => 'doctrine.event_subscriber',
'tag' => 'doctrine.event_listener',
],
'mongodb' => [
'registry' => 'doctrine_mongodb',
'tag' => 'doctrine_mongodb.odm.event_subscriber',
'tag' => 'doctrine_mongodb.odm.event_listener',
],
'couchdb' => [
'registry' => 'doctrine_couchdb',
'tag' => 'doctrine_couchdb.event_subscriber',
'tag' => 'doctrine_couchdb.event_listener',
'listener_class' => 'FOS\UserBundle\Doctrine\CouchDB\UserListener',
],
];
Expand Down Expand Up @@ -97,7 +97,8 @@ public function load(array $configs, ContainerBuilder $container): void

if ($config['use_listener'] && isset(self::$doctrineDrivers[$config['db_driver']])) {
$listenerDefinition = $container->getDefinition('fos_user.user_listener');
$listenerDefinition->addTag(self::$doctrineDrivers[$config['db_driver']]['tag']);
$listenerDefinition->addTag(self::$doctrineDrivers[$config['db_driver']]['tag'], ['event' => 'prePersist']);
$listenerDefinition->addTag(self::$doctrineDrivers[$config['db_driver']]['tag'], ['event' => 'preUpdate']);
if (isset(self::$doctrineDrivers[$config['db_driver']]['listener_class'])) {
$listenerDefinition->setClass(self::$doctrineDrivers[$config['db_driver']]['listener_class']);
}
Expand Down

0 comments on commit c397959

Please sign in to comment.