Skip to content

Commit

Permalink
Fix doctrine listener registration
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Feb 7, 2024
1 parent 111a43e commit 617cf27
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/DependencyInjection/NucleosUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Nucleos\UserBundle\DependencyInjection;

use Doctrine\ORM\Events;
use Nucleos\UserBundle\Mailer\ResettingMailer;
use Nucleos\UserBundle\Model\GroupManager;
use Nucleos\UserBundle\Model\UserManager;
Expand All @@ -35,11 +36,19 @@ final class NucleosUserExtension extends Extension implements PrependExtensionIn
private static array $doctrineDrivers = [
'orm' => [
'registry' => 'doctrine',
'tag' => 'doctrine.event_subscriber',
'tag' => 'doctrine.event_listener',
'events' => [
Events::prePersist,
Events::preUpdate,
],
],
'mongodb' => [
'registry' => 'doctrine_mongodb',
'tag' => 'doctrine_mongodb.odm.event_subscriber',
'tag' => 'doctrine_mongodb.odm.event_listener',
'events' => [
Events::prePersist,
Events::preUpdate,
],
],
];

Expand Down Expand Up @@ -94,10 +103,13 @@ public function load(array $configs, ContainerBuilder $container): void

if ($config['use_listener'] && isset(self::$doctrineDrivers[$config['db_driver']])) {
$listenerDefinition = $container->getDefinition('nucleos_user.user_listener');
$listenerDefinition->addTag(self::$doctrineDrivers[$config['db_driver']]['tag']);
if (isset(self::$doctrineDrivers[$config['db_driver']]['listener_class'])) {
$listenerDefinition->setClass(self::$doctrineDrivers[$config['db_driver']]['listener_class']);
}

foreach (self::$doctrineDrivers[$config['db_driver']]['events'] as $event) {
$listenerDefinition->addTag(self::$doctrineDrivers[$config['db_driver']]['tag'], ['event' => $event]);
}
}

$this->remapParametersNamespaces($config, $container, [
Expand Down

0 comments on commit 617cf27

Please sign in to comment.