From 7ed961e57e432b7065e08d195c70bacc20eeff4c Mon Sep 17 00:00:00 2001 From: Max Baldanza Date: Thu, 14 Dec 2023 14:38:10 +0000 Subject: [PATCH] Add check for lazy object interface In Symfony 6.4 lazy loading of ghost proxies is the default. This means if using 6.4 components with the 5.4 version of the doctrine bridge you get the following error when trying to reset the entity manager: ``` Resetting a non-lazy manager service is not supported. Declare the "doctrine.orm.default_entity_manager" service as lazy. ``` The entity manager is set as lazy already in our case but it extends `\Symfony\Component\VarExporter\LazyObjectInterface` instead of the `LazyLoadingInterface` --- src/Symfony/Bridge/Doctrine/ManagerRegistry.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php index c27a743512764..c3d48fc558518 100644 --- a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php +++ b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php @@ -16,6 +16,7 @@ use ProxyManager\Proxy\LazyLoadingInterface; use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator; use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\VarExporter\LazyObjectInterface; /** * References Doctrine connections and entity/document managers. @@ -51,6 +52,13 @@ protected function resetService($name) } $manager = $this->container->get($name); + if ($manager instanceof LazyObjectInterface) { + if (!$manager->resetLazyObject()) { + throw new \LogicException(sprintf('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy.', $name)); + } + + return; + } if (!$manager instanceof LazyLoadingInterface) { throw new \LogicException('Resetting a non-lazy manager service is not supported. '.(interface_exists(LazyLoadingInterface::class) && class_exists(RuntimeInstantiator::class) ? sprintf('Declare the "%s" service as lazy.', $name) : 'Try running "composer require symfony/proxy-manager-bridge".')); }