diff --git a/DependencyInjection/Compiler/CacheSchemaSubscriberPass.php b/DependencyInjection/Compiler/CacheSchemaSubscriberPass.php
new file mode 100644
index 000000000..daa778038
--- /dev/null
+++ b/DependencyInjection/Compiler/CacheSchemaSubscriberPass.php
@@ -0,0 +1,44 @@
+hasDefinition($subscriberId)) {
+ return;
+ }
+
+ $cacheAdaptersReferences = [];
+ foreach ($container->getDefinitions() as $id => $definition) {
+ if ($definition->isAbstract() || $definition->isSynthetic()) {
+ continue;
+ }
+
+ if ($definition->getClass() !== PdoAdapter::class) {
+ continue;
+ }
+
+ $cacheAdaptersReferences[] = new Reference($id);
+ }
+
+ $container->getDefinition($subscriberId)
+ ->replaceArgument(0, $cacheAdaptersReferences);
+ }
+}
diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php
index 0c0c6d4e9..bdb4b3e60 100644
--- a/DependencyInjection/DoctrineExtension.php
+++ b/DependencyInjection/DoctrineExtension.php
@@ -12,6 +12,8 @@
use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber;
use Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware;
use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor;
+use Symfony\Bridge\Doctrine\SchemaListener\MessengerTransportDoctrineSchemaSubscriber;
+use Symfony\Bridge\Doctrine\SchemaListener\PdoCacheAdapterDoctrineSchemaSubscriber;
use Symfony\Bridge\Doctrine\Validator\DoctrineLoader;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\DoctrineProvider;
@@ -339,6 +341,11 @@ protected function ormLoad(array $config, ContainerBuilder $container)
$container->getDefinition('form.type.entity')->addTag('kernel.reset', ['method' => 'reset']);
}
+ // available in Symfony 5.1 and higher
+ if (! class_exists(PdoCacheAdapterDoctrineSchemaSubscriber::class)) {
+ $container->removeDefinition('doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber');
+ }
+
$entityManagers = [];
foreach (array_keys($config['entity_managers']) as $name) {
$entityManagers[$name] = sprintf('doctrine.orm.%s_entity_manager', $name);
@@ -842,6 +849,11 @@ private function loadMessengerServices(ContainerBuilder $container) : void
$container->removeDefinition('doctrine.orm.messenger.event_subscriber.doctrine_clear_entity_manager');
}
+ // available in Symfony 5.1 and higher
+ if (! class_exists(MessengerTransportDoctrineSchemaSubscriber::class)) {
+ $container->removeDefinition('doctrine.orm.messenger.doctrine_schema_subscriber');
+ }
+
$transportFactoryDefinition = $container->getDefinition('messenger.transport.doctrine.factory');
if (! class_exists(DoctrineTransportFactory::class)) {
// If symfony/messenger < 5.1
diff --git a/DoctrineBundle.php b/DoctrineBundle.php
index f19a1e527..f0ac519de 100644
--- a/DoctrineBundle.php
+++ b/DoctrineBundle.php
@@ -2,6 +2,7 @@
namespace Doctrine\Bundle\DoctrineBundle;
+use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\CacheSchemaSubscriberPass;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DbalSchemaFilterPass;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\EntityListenerPass;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass;
@@ -40,6 +41,7 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new ServiceRepositoryCompilerPass());
$container->addCompilerPass(new WellKnownSchemaFilterPass());
$container->addCompilerPass(new DbalSchemaFilterPass());
+ $container->addCompilerPass(new CacheSchemaSubscriberPass(), PassConfig::TYPE_OPTIMIZE, -10);
}
/**
diff --git a/Resources/config/messenger.xml b/Resources/config/messenger.xml
index 71adb09a7..d5447225e 100644
--- a/Resources/config/messenger.xml
+++ b/Resources/config/messenger.xml
@@ -40,5 +40,10 @@
+
+
+
+
+
diff --git a/Resources/config/orm.xml b/Resources/config/orm.xml
index 3f7510b25..8e06d21fe 100644
--- a/Resources/config/orm.xml
+++ b/Resources/config/orm.xml
@@ -133,6 +133,10 @@
+
+
+
+
diff --git a/Tests/CacheSchemaSubscriberTest.php b/Tests/CacheSchemaSubscriberTest.php
new file mode 100644
index 000000000..85a766723
--- /dev/null
+++ b/Tests/CacheSchemaSubscriberTest.php
@@ -0,0 +1,71 @@
+markTestSkipped('This test requires Symfony 5.1 or higher');
+ }
+
+ $container = new ContainerBuilder(new ParameterBag([
+ 'kernel.name' => 'app',
+ 'kernel.debug' => false,
+ 'kernel.bundles' => [],
+ 'kernel.cache_dir' => sys_get_temp_dir(),
+ 'kernel.environment' => 'test',
+ 'kernel.root_dir' => __DIR__ . '/../../../../', // src dir
+ 'kernel.project_dir' => __DIR__ . '/../../../../', // src dir
+ 'kernel.bundles_metadata' => [],
+ 'kernel.charset' => 'UTF-8',
+ 'kernel.container_class' => ContainerBuilder::class,
+ 'kernel.secret' => 'test',
+ 'env(base64:default::SYMFONY_DECRYPTION_SECRET)' => 'foo',
+ ]));
+
+ $extension = new FrameworkExtension();
+ $container->registerExtension($extension);
+ $extension->load([
+ 'framework' => [
+ 'cache' => [
+ 'pools' => [
+ 'my_cache_adapter' => ['adapter' => 'cache.adapter.pdo'],
+ ],
+ ],
+ ],
+ ], $container);
+
+ $extension = new DoctrineExtension();
+ $container->registerExtension($extension);
+ $extension->load([
+ [
+ 'dbal' => [],
+ 'orm' => [],
+ ],
+ ], $container);
+
+ $container->setAlias('test_subscriber_alias', new Alias('doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber', true));
+ // prevent my_cache_apapter from inlining
+ $container->register('uses_my_cache_adapter', 'stdClass')
+ ->addArgument(new Reference('my_cache_adapter'))
+ ->setPublic(true);
+ $container->addCompilerPass(new CacheSchemaSubscriberPass(), PassConfig::TYPE_OPTIMIZE, -10);
+ $container->compile();
+
+ // check that PdoAdapter service is injected as an argument
+ $definition = $container->findDefinition('test_subscriber_alias');
+ $this->assertEquals([new Reference('my_cache_adapter')], $definition->getArgument(0));
+ }
+}