Skip to content

Commit 07ebbf7

Browse files
tobias-93bobvandevijver
authored andcommitted
Rework Doctrine subscriber registration to fix deprecation
1 parent 8931927 commit 07ebbf7

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

DependencyInjection/BobvEntityHistoryExtension.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Bobv\EntityHistoryBundle\DependencyInjection;
44

5+
use Doctrine\ORM\Events;
6+
use Doctrine\ORM\Tools\ToolEvents;
57
use Symfony\Component\Config\FileLocator;
68
use Symfony\Component\DependencyInjection\ContainerBuilder;
79
use Symfony\Component\DependencyInjection\Loader;
@@ -41,9 +43,11 @@ public function load(array $configs, ContainerBuilder $container): void {
4143
// Create the service tags
4244
foreach ($config['connections'] as $connection) {
4345
$container->findDefinition('bobv.entityhistory.create_schema_subscriber')
44-
->addTag('doctrine.event_subscriber', array('connection' => $connection));
46+
->addTag('doctrine.event_listener', ['event' => ToolEvents::postGenerateSchemaTable, 'connection' => $connection]);
4547
$container->findDefinition('bobv.entityhistory.log_history_subscriber')
46-
->addTag('doctrine.event_subscriber', array('connection' => $connection));
48+
->addTag('doctrine.event_listener', ['event' => Events::onFlush, 'connection' => $connection])
49+
->addTag('doctrine.event_listener', ['event' => Events::postPersist, 'connection' => $connection])
50+
->addTag('doctrine.event_listener', ['event' => Events::postUpdate, 'connection' => $connection]);
4751
}
4852

4953
}

EventSubscriber/CreateSchemaSubscriber.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
namespace Bobv\EntityHistoryBundle\EventSubscriber;
44

55
use Bobv\EntityHistoryBundle\Configuration\HistoryConfiguration;
6-
use Doctrine\Common\EventSubscriber;
76
use Doctrine\DBAL\Schema\Column;
87
use Doctrine\ORM\Tools\Event\GenerateSchemaTableEventArgs;
9-
use Doctrine\ORM\Tools\ToolEvents;
108

119
/**
1210
* Based on the work of
@@ -16,19 +14,12 @@
1614
*
1715
* @author BobV
1816
*/
19-
class CreateSchemaSubscriber implements EventSubscriber
17+
class CreateSchemaSubscriber
2018
{
2119
public function __construct(private readonly HistoryConfiguration $configuration)
2220
{
2321
}
2422

25-
public function getSubscribedEvents(): array
26-
{
27-
return [
28-
ToolEvents::postGenerateSchemaTable
29-
];
30-
}
31-
3223
public function postGenerateSchemaTable(GenerateSchemaTableEventArgs $eventArgs): void
3324
{
3425
$cm = $eventArgs->getClassMetadata();

EventSubscriber/LogHistorySubscriber.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
namespace Bobv\EntityHistoryBundle\EventSubscriber;
44

55
use Bobv\EntityHistoryBundle\Configuration\HistoryConfiguration;
6-
use Doctrine\Common\EventSubscriber;
76
use Doctrine\DBAL\Connection;
87
use Doctrine\DBAL\Platforms\AbstractPlatform;
98
use Doctrine\DBAL\Types\Type;
109
use Doctrine\ORM\EntityManager;
1110
use Doctrine\ORM\Event\OnFlushEventArgs;
1211
use Doctrine\ORM\Event\PostPersistEventArgs;
1312
use Doctrine\ORM\Event\PostUpdateEventArgs;
14-
use Doctrine\ORM\Events;
1513
use Doctrine\ORM\Mapping\ClassMetadata;
1614
use Doctrine\ORM\UnitOfWork;
1715

@@ -23,7 +21,7 @@
2321
*
2422
* @author BobV
2523
*/
26-
class LogHistorySubscriber implements EventSubscriber
24+
class LogHistorySubscriber
2725
{
2826
/**
2927
* @var Connection
@@ -49,10 +47,6 @@ class LogHistorySubscriber implements EventSubscriber
4947
public function __construct(private readonly HistoryConfiguration $config) {
5048
}
5149

52-
public function getSubscribedEvents(): array {
53-
return array(Events::onFlush, Events::postPersist, Events::postUpdate);
54-
}
55-
5650
public function onFlush(OnFlushEventArgs $eventArgs): void {
5751
$this->em = $eventArgs->getObjectManager();
5852
$this->conn = $this->em->getConnection();

0 commit comments

Comments
 (0)