Skip to content

Commit ee88cc4

Browse files
[DependencyInjection] Use lazy-loading ghost object proxies out of the box
1 parent 6e1af48 commit ee88cc4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ManagerRegistry.php

Lines changed: 9 additions & 1 deletion
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\LazyGhostObjectInterface;
1920

2021
/**
2122
* References Doctrine connections and entity/document managers.
@@ -47,8 +48,15 @@ protected function resetService($name): void
4748
}
4849
$manager = $this->container->get($name);
4950

51+
if ($manager instanceof LazyGhostObjectInterface) {
52+
if (!$manager->resetLazyGhostObject()) {
53+
throw new \LogicException(sprintf('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy.', $name));
54+
}
55+
56+
return;
57+
}
5058
if (!$manager instanceof LazyLoadingInterface) {
51-
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".'));
59+
throw new \LogicException(sprintf('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy.', $name));
5260
}
5361
if ($manager instanceof GhostObjectInterface) {
5462
throw new \LogicException('Resetting a lazy-ghost-object manager service is not supported.');

0 commit comments

Comments
 (0)