Skip to content

Commit 0c5e5ad

Browse files
committed
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`
1 parent e82ccb8 commit 0c5e5ad

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ManagerRegistry.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ProxyManager\Proxy\LazyLoadingInterface;
1717
use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
1818
use Symfony\Component\DependencyInjection\Container;
19+
use Symfony\Component\VarExporter\LazyObjectInterface;
1920

2021
/**
2122
* References Doctrine connections and entity/document managers.
@@ -51,6 +52,13 @@ protected function resetService($name)
5152
}
5253
$manager = $this->container->get($name);
5354

55+
if ($manager instanceof LazyObjectInterface) {
56+
if (!$manager->resetLazyObject()) {
57+
throw new \LogicException(sprintf('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy.', $name));
58+
}
59+
60+
return;
61+
}
5462
if (!$manager instanceof LazyLoadingInterface) {
5563
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".'));
5664
}

0 commit comments

Comments
 (0)